/[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.188 Revision 1.209
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.188 2007/08/31 17:45:24 solar Exp $ 4 * $Header: /var/cvsroot/gentoo-projects/pax-utils/Attic/scanelf.c,v 1.209 2009/03/15 08:53:29 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.188 2007/08/31 17:45:24 solar Exp $"; 10static const char *rcsid = "$Id: scanelf.c,v 1.209 2009/03/15 08:53:29 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 == '+')
38static char scan_archives = 0; 38static char scan_archives = 0;
39static char dir_recurse = 0; 39static char dir_recurse = 0;
40static char dir_crossmount = 1; 40static char dir_crossmount = 1;
41static char show_pax = 0; 41static char show_pax = 0;
42static char show_perms = 0; 42static char show_perms = 0;
43static char show_size = 0;
43static char show_phdr = 0; 44static char show_phdr = 0;
44static char show_textrel = 0; 45static char show_textrel = 0;
45static char show_rpath = 0; 46static char show_rpath = 0;
46static char show_needed = 0; 47static char show_needed = 0;
47static char show_interp = 0; 48static char show_interp = 0;
48static char show_bind = 0; 49static char show_bind = 0;
49static char show_soname = 0; 50static char show_soname = 0;
50static char show_textrels = 0; 51static char show_textrels = 0;
51static char show_banner = 1; 52static char show_banner = 1;
52static char show_endian = 0; 53static char show_endian = 0;
54static char show_osabi = 0;
55static char show_eabi = 0;
53static char be_quiet = 0; 56static char be_quiet = 0;
54static char be_verbose = 0; 57static char be_verbose = 0;
55static char be_wewy_wewy_quiet = 0; 58static char be_wewy_wewy_quiet = 0;
56static char be_semi_verbose = 0; 59static char be_semi_verbose = 0;
57static char *find_sym = NULL, *versioned_symname = NULL; 60static char *find_sym = NULL;
58static char *find_lib = NULL; 61static char *find_lib = NULL;
59static char *find_section = NULL; 62static char *find_section = NULL;
60static char *out_format = NULL; 63static char *out_format = NULL;
61static char *search_path = NULL; 64static char *search_path = NULL;
62static char fix_elf = 0; 65static char fix_elf = 0;
65 68
66static char **qa_textrels = NULL; 69static char **qa_textrels = NULL;
67static char **qa_execstack = NULL; 70static char **qa_execstack = NULL;
68static char **qa_wx_load = NULL; 71static char **qa_wx_load = NULL;
69 72
70int match_bits = 0; 73static int match_bits = 0;
71unsigned int match_perms = 0; 74static unsigned int match_perms = 0;
72caddr_t ldcache = 0; 75static caddr_t ldcache = 0;
73size_t ldcache_size = 0; 76static size_t ldcache_size = 0;
74unsigned long setpax = 0UL; 77static unsigned long setpax = 0UL;
75 78
76int has_objdump = 0; 79static int has_objdump = 0;
77
78static char *getstr_perms(const char *fname);
79static char *getstr_perms(const char *fname)
80{
81 struct stat st;
82 static char buf[8];
83
84 if ((stat(fname, &st)) == (-1))
85 return (char *) "";
86
87 snprintf(buf, sizeof(buf), "%o", st.st_mode);
88
89 return (char *) buf + 2;
90}
91 80
92/* find the path to a file by name */ 81/* find the path to a file by name */
93static char *which(const char *fname) 82static char *which(const char *fname)
94{ 83{
95 static char fullpath[BUFSIZ]; 84 static char fullpath[__PAX_UTILS_PATH_MAX];
96 char *path, *p; 85 char *path, *p;
97 86
98 path = getenv("PATH"); 87 path = getenv("PATH");
99 if (!path) 88 if (!path)
100 return NULL; 89 return NULL;
101 90
102 path = xstrdup(path); 91 path = xstrdup(path);
103 while ((p = strrchr(path, ':')) != NULL) { 92 while ((p = strrchr(path, ':')) != NULL) {
104 snprintf(fullpath, sizeof(fullpath), "%s/%s", p + 1, fname); 93 snprintf(fullpath, sizeof(fullpath), "%s/%s", p + 1, fname);
105 *p = 0; 94 *p = 0;
106 if (access(fullpath, R_OK) != (-1)) { 95 if (access(fullpath, R_OK) != -1) {
107 free(path); 96 free(path);
108 return (char *) fullpath; 97 return fullpath;
109 } 98 }
110 } 99 }
111 free(path); 100 free(path);
112 return NULL; 101 return NULL;
113} 102}
118 regex_t preg; 107 regex_t preg;
119 int ret; 108 int ret;
120 109
121 if ((match == NULL) || (regex == NULL)) 110 if ((match == NULL) || (regex == NULL))
122 return EXIT_FAILURE; 111 return EXIT_FAILURE;
123
124 112
125 if ((ret = regcomp(&preg, regex, cflags))) { 113 if ((ret = regcomp(&preg, regex, cflags))) {
126 char err[256]; 114 char err[256];
127 115
128 if (regerror(ret, &preg, err, sizeof(err))) 116 if (regerror(ret, &preg, err, sizeof(err)))
197 } \ 185 } \
198 } 186 }
199 SHOW_PAX(32) 187 SHOW_PAX(32)
200 SHOW_PAX(64) 188 SHOW_PAX(64)
201 } 189 }
202
203 190
204 if (fix_elf && setpax) { 191 if (fix_elf && setpax) {
205 /* set the chpax settings */ 192 /* set the chpax settings */
206 if (elf->elf_class == ELFCLASS32) { 193 if (elf->elf_class == ELFCLASS32) {
207 if (EHDR32(elf->ehdr)->e_type == ET_DYN || EHDR32(elf->ehdr)->e_type == ET_EXEC) 194 if (EHDR32(elf->ehdr)->e_type == ET_DYN || EHDR32(elf->ehdr)->e_type == ET_EXEC)
486 printf(" [0x%lX]\n", (unsigned long)offset_tmp); \ 473 printf(" [0x%lX]\n", (unsigned long)offset_tmp); \
487 if (be_verbose && has_objdump) { \ 474 if (be_verbose && has_objdump) { \
488 Elf ## B ## _Addr end_addr = offset_tmp + EGET(func->st_size); \ 475 Elf ## B ## _Addr end_addr = offset_tmp + EGET(func->st_size); \
489 char *sysbuf; \ 476 char *sysbuf; \
490 size_t syslen; \ 477 size_t syslen; \
478 int sysret; \
491 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"; \
492 syslen = sizeof(sysfmt) + strlen(elf->filename) + 3 * sizeof(unsigned long) + 1; \ 480 syslen = sizeof(sysfmt) + strlen(elf->filename) + 3 * sizeof(unsigned long) + 1; \
493 sysbuf = xmalloc(syslen); \ 481 sysbuf = xmalloc(syslen); \
494 if (end_addr < r_offset) \ 482 if (end_addr < r_offset) \
495 /* not uncommon when things are optimized out */ \ 483 /* not uncommon when things are optimized out */ \
498 (unsigned long)offset_tmp, \ 486 (unsigned long)offset_tmp, \
499 (unsigned long)end_addr, \ 487 (unsigned long)end_addr, \
500 elf->filename, \ 488 elf->filename, \
501 (unsigned long)r_offset); \ 489 (unsigned long)r_offset); \
502 fflush(stdout); \ 490 fflush(stdout); \
503 system(sysbuf); \ 491 sysret = system(sysbuf); \
504 fflush(stdout); \ 492 fflush(stdout); \
505 free(sysbuf); \ 493 free(sysbuf); \
506 } \ 494 } \
507 } \ 495 } \
508 } } 496 } }
737 ldcache_size = st.st_size; 725 ldcache_size = st.st_size;
738 ldcache = mmap(0, ldcache_size, PROT_READ, MAP_SHARED, fd, 0); 726 ldcache = mmap(0, ldcache_size, PROT_READ, MAP_SHARED, fd, 0);
739 727
740 close(fd); 728 close(fd);
741 729
742 if (ldcache == (caddr_t)-1) { 730 if (ldcache == MAP_FAILED) {
743 ldcache = 0; 731 ldcache = 0;
744 return NULL; 732 return NULL;
745 } 733 }
746 734
747 if (memcmp(((header_t *) ldcache)->magic, LDSO_CACHE_MAGIC, LDSO_CACHE_MAGIC_LEN)) 735 if (memcmp(((header_t *) ldcache)->magic, LDSO_CACHE_MAGIC, LDSO_CACHE_MAGIC_LEN))
793 781
794 /* not found in any path */ 782 /* not found in any path */
795 return NULL; 783 return NULL;
796} 784}
797#else 785#else
786#ifdef __ELF__
798#warning Cache support not implemented for your target 787#warning Cache support not implemented for your target
788#endif
799static char *lookup_cache_lib(elfobj *elf, char *fname) 789static char *lookup_cache_lib(elfobj *elf, char *fname)
800{ 790{
801 return NULL; 791 return NULL;
802} 792}
803#endif 793#endif
972 } 962 }
973 963
974 return NULL; 964 return NULL;
975} 965}
976 966
967static int scanelf_match_symname(const char *symname, const char *tomatch) {
968 /* We do things differently when checking with regexp */
969 if (g_match) {
970 return rematch(symname, tomatch, REG_EXTENDED) == 0;
971 } else {
972 const size_t symname_len = strlen(symname);
973 return (strncmp(symname, tomatch, symname_len) == 0 &&
974 /* Accept unversioned symbol names */
975 (tomatch[symname_len] == '\0' || tomatch[symname_len] == '@'));
976 }
977}
978
977static char *scanelf_file_sym(elfobj *elf, char *found_sym) 979static char *scanelf_file_sym(elfobj *elf, char *found_sym)
978{ 980{
979 unsigned long i; 981 unsigned long i;
980 char *ret; 982 char *ret;
981 void *symtab_void, *strtab_void; 983 void *symtab_void, *strtab_void;
994 unsigned long cnt = EGET(symtab->sh_entsize); \ 996 unsigned long cnt = EGET(symtab->sh_entsize); \
995 char *symname; \ 997 char *symname; \
996 if (cnt) \ 998 if (cnt) \
997 cnt = EGET(symtab->sh_size) / cnt; \ 999 cnt = EGET(symtab->sh_size) / cnt; \
998 for (i = 0; i < cnt; ++i) { \ 1000 for (i = 0; i < cnt; ++i) { \
1001 if ((void*)sym > (void*)elf->data_end) { \
1002 warnf("%s: corrupt ELF symbols - aborting", elf->filename); \
1003 goto break_out; \
1004 } \
999 if (sym->st_name) { \ 1005 if (sym->st_name) { \
1000 /* make sure the symbol name is in acceptable memory range */ \ 1006 /* make sure the symbol name is in acceptable memory range */ \
1001 symname = (char *)(elf->data + EGET(strtab->sh_offset) + EGET(sym->st_name)); \ 1007 symname = (char *)(elf->data + EGET(strtab->sh_offset) + EGET(sym->st_name)); \
1002 if ((void*)symname > (void*)elf->data_end) { \ 1008 if ((void*)symname > (void*)elf->data_end) { \
1003 warnf("%s: corrupt ELF symbols", elf->filename); \ 1009 warnf("%s: corrupt ELF symbols", elf->filename); \
1004 ++sym; \ 1010 ++sym; \
1005 continue; \ 1011 continue; \
1006 } \ 1012 } \
1007 /* debug display ... show all symbols and some extra info */ \ 1013 /* debug display ... show all symbols and some extra info */ \
1008 if (g_match ? rematch(ret, symname, REG_EXTENDED) == 0 : *ret == '*') { \ 1014 if (0 && g_match ? rematch(ret, symname, REG_EXTENDED) == 0 : *ret == '*') { \
1009 printf("%s(%s) %5lX %15s %s %s\n", \ 1015 printf("%s(%s) %5lX %15s %s %s\n", \
1010 ((*found_sym == 0) ? "\n\t" : "\t"), \ 1016 ((*found_sym == 0) ? "\n\t" : "\t"), \
1011 elf->base_filename, \ 1017 elf->base_filename, \
1012 (unsigned long)sym->st_size, \ 1018 (unsigned long)sym->st_size, \
1013 get_elfstttype(sym->st_info), \ 1019 get_elfstttype(sym->st_info), \
1014 sym->st_shndx == SHN_UNDEF ? "U" : "D", symname); \ 1020 sym->st_shndx == SHN_UNDEF ? "U" : "D", symname); \
1015 *found_sym = 1; \ 1021 *found_sym = 1; \
1016 } else { \ 1022 } else { \
1017 /* allow the user to specify a comma delimited list of symbols to search for */ \ 1023 /* allow the user to specify a comma delimited list of symbols to search for */ \
1018 char *this_sym, *this_sym_ver, *next_sym; \ 1024 char *this_sym, *next_sym; \
1019 this_sym = ret; \ 1025 next_sym = ret; \
1020 this_sym_ver = versioned_symname; \ 1026 while (next_sym) { \
1021 do { \ 1027 this_sym = next_sym; \
1022 next_sym = strchr(this_sym, ','); \ 1028 if ((next_sym = strchr(this_sym, ','))) \
1023 if (next_sym == NULL) \ 1029 next_sym += 1; /* Skip the comma */ \
1024 next_sym = this_sym + strlen(this_sym); \
1025 /* do we want a defined symbol ? */ \ 1030 /* do we want a defined symbol ? */ \
1026 if (*this_sym == '+') { \ 1031 if (*this_sym == '+') { \
1027 if (sym->st_shndx == SHN_UNDEF) \ 1032 if (sym->st_shndx == SHN_UNDEF) \
1028 goto skip_this_sym##B; \ 1033 continue; \
1029 ++this_sym; \ 1034 ++this_sym; \
1030 ++this_sym_ver; \
1031 /* do we want an undefined symbol ? */ \ 1035 /* do we want an undefined symbol ? */ \
1032 } else if (*this_sym == '-') { \ 1036 } else if (*this_sym == '-') { \
1033 if (sym->st_shndx != SHN_UNDEF) \ 1037 if (sym->st_shndx != SHN_UNDEF) \
1034 goto skip_this_sym##B; \ 1038 continue; \
1035 ++this_sym; \ 1039 ++this_sym; \
1036 ++this_sym_ver; \
1037 } \ 1040 } \
1041 if (next_sym) /* Copy it so that we don't have to worry about the final , */ \
1042 this_sym = xstrndup(this_sym, next_sym-this_sym); \
1038 /* ok, lets compare the name now */ \ 1043 /* ok, lets compare the name now */ \
1039 if ((strncmp(this_sym, symname, (next_sym-this_sym)) == 0 && symname[next_sym-this_sym] == '\0') || \ 1044 if (scanelf_match_symname(this_sym, symname)) { \
1040 (strncmp(this_sym_ver, symname, strlen(this_sym_ver)) == 0)) { \
1041 if (be_semi_verbose) { \ 1045 if (be_semi_verbose) { \
1042 char buf[126]; \ 1046 char buf[126]; \
1043 snprintf(buf, sizeof(buf), "%lX %s %s", \ 1047 snprintf(buf, sizeof(buf), "%lX %s %s", \
1044 (unsigned long)sym->st_size, get_elfstttype(sym->st_info), this_sym); \ 1048 (unsigned long)sym->st_size, get_elfstttype(sym->st_info), this_sym); \
1045 ret = buf; \ 1049 ret = buf; \
1046 } else \ 1050 } else \
1047 ret = this_sym; \ 1051 ret = symname; \
1048 (*found_sym)++; \ 1052 (*found_sym)++; \
1049 goto break_out; \ 1053 goto break_out; \
1050 } \ 1054 } \
1051 skip_this_sym##B: this_sym = next_sym + 1; \ 1055 if (next_sym) free(this_sym); \
1052 } while (*next_sym != '\0'); \ 1056 } \
1053 } \ 1057 } \
1054 } \ 1058 } \
1055 ++sym; \ 1059 ++sym; \
1056 } } 1060 } }
1057 FIND_SYM(32) 1061 FIND_SYM(32)
1066 if (be_quiet) 1070 if (be_quiet)
1067 return NULL; 1071 return NULL;
1068 else 1072 else
1069 return (char *)" - "; 1073 return (char *)" - ";
1070} 1074}
1071
1072 1075
1073static char *scanelf_file_sections(elfobj *elf, char *found_section) 1076static char *scanelf_file_sections(elfobj *elf, char *found_section)
1074{ 1077{
1075 if (!find_section) 1078 if (!find_section)
1076 return NULL; 1079 return NULL;
1147 case 'r': prints("RPATH "); break; 1150 case 'r': prints("RPATH "); break;
1148 case 'M': prints("CLASS "); break; 1151 case 'M': prints("CLASS "); break;
1149 case 'n': prints("NEEDED "); break; 1152 case 'n': prints("NEEDED "); break;
1150 case 'i': prints("INTERP "); break; 1153 case 'i': prints("INTERP "); break;
1151 case 'b': prints("BIND "); break; 1154 case 'b': prints("BIND "); break;
1155 case 'Z': prints("SIZE "); break;
1152 case 'S': prints("SONAME "); break; 1156 case 'S': prints("SONAME "); break;
1153 case 's': prints("SYM "); break; 1157 case 's': prints("SYM "); break;
1154 case 'N': prints("LIB "); break; 1158 case 'N': prints("LIB "); break;
1155 case 'T': prints("TEXTRELS "); break; 1159 case 'T': prints("TEXTRELS "); break;
1156 case 'k': prints("SECTION "); break; 1160 case 'k': prints("SECTION "); break;
1157 case 'a': prints("ARCH "); break; 1161 case 'a': prints("ARCH "); break;
1162 case 'I': prints("OSABI "); break;
1163 case 'Y': prints("EABI "); break;
1158 case 'O': prints("PERM "); break; 1164 case 'O': prints("PERM "); break;
1159 case 'D': prints("ENDIAN "); break; 1165 case 'D': prints("ENDIAN "); break;
1160 default: warnf("'%c' has no title ?", out_format[i]); 1166 default: warnf("'%c' has no title ?", out_format[i]);
1161 } 1167 }
1162 } 1168 }
1168 1174
1169 /* dump all the good stuff */ 1175 /* dump all the good stuff */
1170 for (i = 0; out_format[i]; ++i) { 1176 for (i = 0; out_format[i]; ++i) {
1171 const char *out; 1177 const char *out;
1172 const char *tmp; 1178 const char *tmp;
1173 1179 static char ubuf[sizeof(unsigned long)*2];
1174 if (!IS_MODIFIER(out_format[i])) { 1180 if (!IS_MODIFIER(out_format[i])) {
1175 xchrcat(&out_buffer, out_format[i], &out_len); 1181 xchrcat(&out_buffer, out_format[i], &out_len);
1176 continue; 1182 continue;
1177 } 1183 }
1178 1184
1216 case 't': out = scanelf_file_textrel(elf, &found_textrel); break; 1222 case 't': out = scanelf_file_textrel(elf, &found_textrel); break;
1217 case 'T': out = scanelf_file_textrels(elf, &found_textrels, &found_textrel); break; 1223 case 'T': out = scanelf_file_textrels(elf, &found_textrels, &found_textrel); break;
1218 case 'r': scanelf_file_rpath(elf, &found_rpath, &out_buffer, &out_len); break; 1224 case 'r': scanelf_file_rpath(elf, &found_rpath, &out_buffer, &out_len); break;
1219 case 'M': out = get_elfeitype(EI_CLASS, elf->data[EI_CLASS]); break; 1225 case 'M': out = get_elfeitype(EI_CLASS, elf->data[EI_CLASS]); break;
1220 case 'D': out = get_endian(elf); break; 1226 case 'D': out = get_endian(elf); break;
1221 case 'O': out = getstr_perms(elf->filename); break; 1227 case 'O': out = strfileperms(elf->filename); break;
1222 case 'n': 1228 case 'n':
1223 case 'N': out = scanelf_file_needed_lib(elf, &found_needed, &found_lib, (out_format[i]=='N'), &out_buffer, &out_len); break; 1229 case 'N': out = scanelf_file_needed_lib(elf, &found_needed, &found_lib, (out_format[i]=='N'), &out_buffer, &out_len); break;
1224 case 'i': out = scanelf_file_interp(elf, &found_interp); break; 1230 case 'i': out = scanelf_file_interp(elf, &found_interp); break;
1225 case 'b': out = scanelf_file_bind(elf, &found_bind); break; 1231 case 'b': out = scanelf_file_bind(elf, &found_bind); break;
1226 case 'S': out = scanelf_file_soname(elf, &found_soname); break; 1232 case 'S': out = scanelf_file_soname(elf, &found_soname); break;
1227 case 's': out = scanelf_file_sym(elf, &found_sym); break; 1233 case 's': out = scanelf_file_sym(elf, &found_sym); break;
1228 case 'k': out = scanelf_file_sections(elf, &found_section); break; 1234 case 'k': out = scanelf_file_sections(elf, &found_section); break;
1229 case 'a': out = get_elfemtype(elf); break; 1235 case 'a': out = get_elfemtype(elf); break;
1236 case 'I': out = get_elfosabi(elf); break;
1237 case 'Y': out = get_elf_eabi(elf); break;
1238 case 'Z': snprintf(ubuf, sizeof(ubuf), "%lu", (unsigned long)elf->len); out = ubuf; break;;
1230 default: warnf("'%c' has no scan code?", out_format[i]); 1239 default: warnf("'%c' has no scan code?", out_format[i]);
1231 } 1240 }
1232 if (out) { 1241 if (out) {
1233 /* hack for comma delimited output like `scanelf -s sym1,sym2,sym3` */ 1242 /* hack for comma delimited output like `scanelf -s sym1,sym2,sym3` */
1234 if (out_format[i] == 's' && (tmp=strchr(out,',')) != NULL) 1243 if (out_format[i] == 's' && (tmp=strchr(out,',')) != NULL)
1310 1319
1311 ar = ar_open_fd(filename, fd); 1320 ar = ar_open_fd(filename, fd);
1312 if (ar == NULL) 1321 if (ar == NULL)
1313 return 1; 1322 return 1;
1314 1323
1315 ar_buffer = (char*)mmap(0, len, PROT_READ | (fix_elf ? PROT_WRITE : 0), (fix_elf ? MAP_SHARED : MAP_PRIVATE), fd, 0); 1324 ar_buffer = mmap(0, len, PROT_READ | (fix_elf ? PROT_WRITE : 0), (fix_elf ? MAP_SHARED : MAP_PRIVATE), fd, 0);
1316 while ((m=ar_next(ar)) != NULL) { 1325 while ((m=ar_next(ar)) != NULL) {
1317 elf = readelf_buffer(m->name, ar_buffer+lseek(fd,0,SEEK_CUR), m->size); 1326 elf = readelf_buffer(m->name, ar_buffer+lseek(fd,0,SEEK_CUR), m->size);
1318 if (elf) { 1327 if (elf) {
1319 scanelf_elfobj(elf); 1328 scanelf_elfobj(elf);
1320 unreadelf(elf); 1329 unreadelf(elf);
1538 fclose(fp); 1547 fclose(fp);
1539 return i; 1548 return i;
1540} 1549}
1541 1550
1542#else 1551#else
1543 1552#ifdef __ELF__
1544#warning Cache config support not implemented for your target 1553#warning Cache config support not implemented for your target
1554#endif
1545static int load_ld_cache_config(int i, const char *fname) 1555static int load_ld_cache_config(int i, const char *fname)
1546{ 1556{
1547 memset(ldpaths, 0x00, sizeof(ldpaths)); 1557 memset(ldpaths, 0x00, sizeof(ldpaths));
1558 return 0;
1548} 1559}
1549
1550#endif 1560#endif
1551 1561
1552/* scan /etc/ld.so.conf for paths */ 1562/* scan /etc/ld.so.conf for paths */
1553static void scanelf_ldpath(void) 1563static void scanelf_ldpath(void)
1554{ 1564{
1589 } 1599 }
1590 1600
1591 free(path); 1601 free(path);
1592} 1602}
1593 1603
1594
1595/* usage / invocation handling functions */ /* Free Flags: c d j u w C G H I J K P Q U W Y Z */ 1604/* usage / invocation handling functions */ /* Free Flags: c d j u w C G H J K P Q U W */
1596#define PARSE_FLAGS "plRmyAXz:xetrnLibSs:k:gN:TaqvF:f:o:E:M:DO:BhV" 1605#define PARSE_FLAGS "plRmyAXz:xetrnLibSs:k:gN:TaqvF:f:o:E:M:DIYO:ZBhV"
1597#define a_argument required_argument 1606#define a_argument required_argument
1598static struct option const long_opts[] = { 1607static struct option const long_opts[] = {
1599 {"path", no_argument, NULL, 'p'}, 1608 {"path", no_argument, NULL, 'p'},
1600 {"ldpath", no_argument, NULL, 'l'}, 1609 {"ldpath", no_argument, NULL, 'l'},
1601 {"recursive", no_argument, NULL, 'R'}, 1610 {"recursive", no_argument, NULL, 'R'},
1619 {"gmatch", no_argument, NULL, 'g'}, 1628 {"gmatch", no_argument, NULL, 'g'},
1620 {"textrels", no_argument, NULL, 'T'}, 1629 {"textrels", no_argument, NULL, 'T'},
1621 {"etype", a_argument, NULL, 'E'}, 1630 {"etype", a_argument, NULL, 'E'},
1622 {"bits", a_argument, NULL, 'M'}, 1631 {"bits", a_argument, NULL, 'M'},
1623 {"endian", no_argument, NULL, 'D'}, 1632 {"endian", no_argument, NULL, 'D'},
1633 {"osabi", no_argument, NULL, 'I'},
1634 {"eabi", no_argument, NULL, 'Y'},
1624 {"perms", a_argument, NULL, 'O'}, 1635 {"perms", a_argument, NULL, 'O'},
1636 {"size", no_argument, NULL, 'Z'},
1625 {"all", no_argument, NULL, 'a'}, 1637 {"all", no_argument, NULL, 'a'},
1626 {"quiet", no_argument, NULL, 'q'}, 1638 {"quiet", no_argument, NULL, 'q'},
1627 {"verbose", no_argument, NULL, 'v'}, 1639 {"verbose", no_argument, NULL, 'v'},
1628 {"format", a_argument, NULL, 'F'}, 1640 {"format", a_argument, NULL, 'F'},
1629 {"from", a_argument, NULL, 'f'}, 1641 {"from", a_argument, NULL, 'f'},
1658 "Use strncmp to match libraries. (use with -N)", 1670 "Use strncmp to match libraries. (use with -N)",
1659 "Locate cause of TEXTREL", 1671 "Locate cause of TEXTREL",
1660 "Print only ELF files matching etype ET_DYN,ET_EXEC ...", 1672 "Print only ELF files matching etype ET_DYN,ET_EXEC ...",
1661 "Print only ELF files matching numeric bits", 1673 "Print only ELF files matching numeric bits",
1662 "Print Endianness", 1674 "Print Endianness",
1675 "Print OSABI",
1676 "Print EABI (EM_ARM Only)",
1663 "Print only ELF files matching octal permissions", 1677 "Print only ELF files matching octal permissions",
1678 "Print ELF file size",
1664 "Print all scanned info (-x -e -t -r -b)\n", 1679 "Print all scanned info (-x -e -t -r -b)\n",
1665 "Only output 'bad' things", 1680 "Only output 'bad' things",
1666 "Be verbose (can be specified more than once)", 1681 "Be verbose (can be specified more than once)",
1667 "Use specified format for output", 1682 "Use specified format for output",
1668 "Read input stream from a filename", 1683 "Read input stream from a filename",
1733 if (strcmp(optarg, "ELFCLASS64") == 0) 1748 if (strcmp(optarg, "ELFCLASS64") == 0)
1734 match_bits = 64; 1749 match_bits = 64;
1735 } 1750 }
1736 break; 1751 break;
1737 case 'O': 1752 case 'O':
1738 if (sscanf(optarg, "%o", &match_perms) == (-1)) 1753 if (sscanf(optarg, "%o", &match_perms) == -1)
1739 match_bits = 0; 1754 match_bits = 0;
1740 break; 1755 break;
1741 case 'o': { 1756 case 'o': {
1742 if (freopen(optarg, "w", stdout) == NULL) 1757 if (freopen(optarg, "w", stdout) == NULL)
1743 err("Could not open output stream '%s': %s", optarg, strerror(errno)); 1758 err("Could not open output stream '%s': %s", optarg, strerror(errno));
1748 find_section = optarg; 1763 find_section = optarg;
1749 break; 1764 break;
1750 case 's': { 1765 case 's': {
1751 if (find_sym) warn("You prob don't want to specify -s twice"); 1766 if (find_sym) warn("You prob don't want to specify -s twice");
1752 find_sym = optarg; 1767 find_sym = optarg;
1753 versioned_symname = xmalloc(sizeof(char) * (strlen(find_sym)+1+1));
1754 sprintf(versioned_symname, "%s@", find_sym);
1755 break; 1768 break;
1756 } 1769 }
1757 case 'N': { 1770 case 'N': {
1758 if (find_lib) warn("You prob don't want to specify -N twice"); 1771 if (find_lib) warn("You prob don't want to specify -N twice");
1759 find_lib = optarg; 1772 find_lib = optarg;
1806 ((flags & PF_EMUTRAMP) && (flags & PF_NOEMUTRAMP)) || 1819 ((flags & PF_EMUTRAMP) && (flags & PF_NOEMUTRAMP)) ||
1807 ((flags & PF_RANDMMAP) && (flags & PF_NORANDMMAP)))) 1820 ((flags & PF_RANDMMAP) && (flags & PF_NORANDMMAP))))
1808 setpax = flags; 1821 setpax = flags;
1809 break; 1822 break;
1810 } 1823 }
1824 case 'Z': show_size = 1; break;
1811 case 'g': g_match = 1; break; 1825 case 'g': g_match = 1; break;
1812 case 'L': use_ldcache = 1; break; 1826 case 'L': use_ldcache = 1; break;
1813 case 'y': scan_symlink = 0; break; 1827 case 'y': scan_symlink = 0; break;
1814 case 'A': scan_archives = 1; break; 1828 case 'A': scan_archives = 1; break;
1815 case 'B': show_banner = 0; break; 1829 case 'B': show_banner = 0; break;
1829 case 'T': show_textrels = 1; break; 1843 case 'T': show_textrels = 1; break;
1830 case 'q': be_quiet = 1; break; 1844 case 'q': be_quiet = 1; break;
1831 case 'v': be_verbose = (be_verbose % 20) + 1; break; 1845 case 'v': be_verbose = (be_verbose % 20) + 1; break;
1832 case 'a': show_perms = show_pax = show_phdr = show_textrel = show_rpath = show_bind = show_endian = 1; break; 1846 case 'a': show_perms = show_pax = show_phdr = show_textrel = show_rpath = show_bind = show_endian = 1; break;
1833 case 'D': show_endian = 1; break; 1847 case 'D': show_endian = 1; break;
1848 case 'I': show_osabi = 1; break;
1849 case 'Y': show_eabi = 1; break;
1834 case ':': 1850 case ':':
1835 err("Option '%c' is missing parameter", optopt); 1851 err("Option '%c' is missing parameter", optopt);
1836 case '?': 1852 case '?':
1837 err("Unknown option '%c' or argument missing", optopt); 1853 err("Unknown option '%c' or argument missing", optopt);
1838 default: 1854 default:
1845 } 1861 }
1846 /* let the format option override all other options */ 1862 /* let the format option override all other options */
1847 if (out_format) { 1863 if (out_format) {
1848 show_pax = show_phdr = show_textrel = show_rpath = \ 1864 show_pax = show_phdr = show_textrel = show_rpath = \
1849 show_needed = show_interp = show_bind = show_soname = \ 1865 show_needed = show_interp = show_bind = show_soname = \
1850 show_textrels = show_perms = show_endian = 0; 1866 show_textrels = show_perms = show_endian = show_size = \
1867 show_osabi = show_eabi = 0;
1851 for (i = 0; out_format[i]; ++i) { 1868 for (i = 0; out_format[i]; ++i) {
1852 if (!IS_MODIFIER(out_format[i])) continue; 1869 if (!IS_MODIFIER(out_format[i])) continue;
1853 1870
1854 switch (out_format[++i]) { 1871 switch (out_format[++i]) {
1855 case '+': break; 1872 case '+': break;
1862 case 's': break; 1879 case 's': break;
1863 case 'N': break; 1880 case 'N': break;
1864 case 'o': break; 1881 case 'o': break;
1865 case 'a': break; 1882 case 'a': break;
1866 case 'M': break; 1883 case 'M': break;
1884 case 'Z': show_size = 1; break;
1867 case 'D': show_endian = 1; break; 1885 case 'D': show_endian = 1; break;
1886 case 'I': show_osabi = 1; break;
1887 case 'Y': show_eabi = 1; break;
1868 case 'O': show_perms = 1; break; 1888 case 'O': show_perms = 1; break;
1869 case 'x': show_pax = 1; break; 1889 case 'x': show_pax = 1; break;
1870 case 'e': show_phdr = 1; break; 1890 case 'e': show_phdr = 1; break;
1871 case 't': show_textrel = 1; break; 1891 case 't': show_textrel = 1; break;
1872 case 'r': show_rpath = 1; break; 1892 case 'r': show_rpath = 1; break;
1883 1903
1884 /* construct our default format */ 1904 /* construct our default format */
1885 } else { 1905 } else {
1886 size_t fmt_len = 30; 1906 size_t fmt_len = 30;
1887 out_format = xmalloc(sizeof(char) * fmt_len); 1907 out_format = xmalloc(sizeof(char) * fmt_len);
1908 *out_format = '\0';
1888 if (!be_quiet) xstrcat(&out_format, "%o ", &fmt_len); 1909 if (!be_quiet) xstrcat(&out_format, "%o ", &fmt_len);
1889 if (show_pax) xstrcat(&out_format, "%x ", &fmt_len); 1910 if (show_pax) xstrcat(&out_format, "%x ", &fmt_len);
1890 if (show_perms) xstrcat(&out_format, "%O ", &fmt_len); 1911 if (show_perms) xstrcat(&out_format, "%O ", &fmt_len);
1912 if (show_size) xstrcat(&out_format, "%Z ", &fmt_len);
1891 if (show_endian) xstrcat(&out_format, "%D ", &fmt_len); 1913 if (show_endian) xstrcat(&out_format, "%D ", &fmt_len);
1914 if (show_osabi) xstrcat(&out_format, "%I ", &fmt_len);
1915 if (show_eabi) xstrcat(&out_format, "%Y ", &fmt_len);
1892 if (show_phdr) xstrcat(&out_format, "%e ", &fmt_len); 1916 if (show_phdr) xstrcat(&out_format, "%e ", &fmt_len);
1893 if (show_textrel) xstrcat(&out_format, "%t ", &fmt_len); 1917 if (show_textrel) xstrcat(&out_format, "%t ", &fmt_len);
1894 if (show_rpath) xstrcat(&out_format, "%r ", &fmt_len); 1918 if (show_rpath) xstrcat(&out_format, "%r ", &fmt_len);
1895 if (show_needed) xstrcat(&out_format, "%n ", &fmt_len); 1919 if (show_needed) xstrcat(&out_format, "%n ", &fmt_len);
1896 if (show_interp) xstrcat(&out_format, "%i ", &fmt_len); 1920 if (show_interp) xstrcat(&out_format, "%i ", &fmt_len);
1921 search_path = argv[optind++]; 1945 search_path = argv[optind++];
1922 ret = scanelf_dir(search_path); 1946 ret = scanelf_dir(search_path);
1923 } 1947 }
1924 1948
1925 /* clean up */ 1949 /* clean up */
1926 free(versioned_symname);
1927 for (i = 0; ldpaths[i]; ++i) 1950 for (i = 0; ldpaths[i]; ++i)
1928 free(ldpaths[i]); 1951 free(ldpaths[i]);
1929 1952
1930 if (ldcache != 0) 1953 if (ldcache != 0)
1931 munmap(ldcache, ldcache_size); 1954 munmap(ldcache, ldcache_size);
1980 free(qa_textrels); 2003 free(qa_textrels);
1981 free(qa_execstack); 2004 free(qa_execstack);
1982 free(qa_wx_load); 2005 free(qa_wx_load);
1983} 2006}
1984#endif 2007#endif
1985
1986 2008
1987int main(int argc, char *argv[]) 2009int main(int argc, char *argv[])
1988{ 2010{
1989 int ret; 2011 int ret;
1990 if (argc < 2) 2012 if (argc < 2)
1999 "\t- 1 per QA_TEXTRELS/QA_EXECSTACK/QA_WX_LOAD"); 2021 "\t- 1 per QA_TEXTRELS/QA_EXECSTACK/QA_WX_LOAD");
2000#endif 2022#endif
2001 return ret; 2023 return ret;
2002} 2024}
2003 2025
2004
2005/* Match filename against entries in matchlist, return TRUE 2026/* Match filename against entries in matchlist, return TRUE
2006 * if the file is listed */ 2027 * if the file is listed */
2007static int file_matches_list(const char *filename, char **matchlist) 2028static int file_matches_list(const char *filename, char **matchlist)
2008{ 2029{
2009 char **file; 2030 char **file;

Legend:
Removed from v.1.188  
changed lines
  Added in v.1.209

  ViewVC Help
Powered by ViewVC 1.1.20