ldd.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * A small little ldd implementation for uClibc
  4. *
  5. * Copyright (C) 2000-2004 Erik Andersen <andersee@debian.org>
  6. *
  7. * Several functions in this file (specifically, elf_find_section_type(),
  8. * elf_find_phdr_type(), and elf_find_dynamic(), were stolen from elflib.c from
  9. * elfvector (http://www.BitWagon.com/elfvector.html) by John F. Reiser
  10. * <jreiser@BitWagon.com>, which is copyright 2000 BitWagon Software LLC
  11. * (GPL2).
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 2 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  21. * General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  26. *
  27. */
  28. #define _GNU_SOURCE
  29. #include <stdlib.h>
  30. #include <stdio.h>
  31. #include <fcntl.h>
  32. #include <string.h>
  33. #include <unistd.h>
  34. #include <sys/mman.h>
  35. #include <sys/stat.h>
  36. #include <sys/types.h>
  37. #include <sys/types.h>
  38. #include <sys/wait.h>
  39. #include "bswap.h"
  40. #if defined (sun)
  41. #include "link.h"
  42. #else
  43. #include "elf.h"
  44. #endif
  45. #ifdef DMALLOC
  46. #include <dmalloc.h>
  47. #endif
  48. #if defined(__arm__)
  49. #define MATCH_MACHINE(x) (x == EM_ARM)
  50. #define ELFCLASSM ELFCLASS32
  51. #endif
  52. #if defined(__s390__)
  53. #define MATCH_MACHINE(x) (x == EM_S390)
  54. #define ELFCLASSM ELFCLASS32
  55. #endif
  56. #if defined(__i386__)
  57. #ifndef EM_486
  58. #define MATCH_MACHINE(x) (x == EM_386)
  59. #else
  60. #define MATCH_MACHINE(x) (x == EM_386 || x == EM_486)
  61. #endif
  62. #define ELFCLASSM ELFCLASS32
  63. #endif
  64. #if defined(__mc68000__)
  65. #define MATCH_MACHINE(x) (x == EM_68K)
  66. #define ELFCLASSM ELFCLASS32
  67. #endif
  68. #if defined(__mips__)
  69. #define MATCH_MACHINE(x) (x == EM_MIPS || x == EM_MIPS_RS3_LE)
  70. #define ELFCLASSM ELFCLASS32
  71. #endif
  72. #if defined(__powerpc__)
  73. #define MATCH_MACHINE(x) (x == EM_PPC)
  74. #define ELFCLASSM ELFCLASS32
  75. #endif
  76. #if defined(__sh__)
  77. #define MATCH_MACHINE(x) (x == EM_SH)
  78. #define ELFCLASSM ELFCLASS32
  79. #endif
  80. #if defined (__v850e__)
  81. #define MATCH_MACHINE(x) ((x) == EM_V850 || (x) == EM_CYGNUS_V850)
  82. #define ELFCLASSM ELFCLASS32
  83. #endif
  84. #if defined (__sparc__)
  85. #define MATCH_MACHINE(x) ((x) == EM_SPARC || (x) == EM_SPARC32PLUS)
  86. #define ELFCLASSM ELFCLASS32
  87. #endif
  88. #if defined(__cris__)
  89. #define MATCH_MACHINE(x) (x == EM_CRIS)
  90. #define ELFCLASSM ELFCLASS32
  91. #endif
  92. #ifndef MATCH_MACHINE
  93. #warning "You really should add a MATCH_MACHINE() macro for your architecture"
  94. #endif
  95. #if __BYTE_ORDER == __LITTLE_ENDIAN
  96. #define ELFDATAM ELFDATA2LSB
  97. #elif __BYTE_ORDER == __BIG_ENDIAN
  98. #define ELFDATAM ELFDATA2MSB
  99. #endif
  100. struct library {
  101. char *name;
  102. int resolved;
  103. char *path;
  104. struct library *next;
  105. };
  106. struct library *lib_list = NULL;
  107. char not_found[] = "not found";
  108. char *interp = NULL;
  109. char *interp_dir = NULL;
  110. int byteswap;
  111. static int interpreter_already_found=0;
  112. inline uint32_t byteswap32_to_host(uint32_t value)
  113. {
  114. if (byteswap==1) {
  115. return(bswap_32(value));
  116. } else {
  117. return(value);
  118. }
  119. }
  120. Elf32_Shdr * elf_find_section_type( int key, Elf32_Ehdr *ehdr)
  121. {
  122. int j;
  123. Elf32_Shdr *shdr;
  124. shdr = (Elf32_Shdr *)(ehdr->e_shoff + (char *)ehdr);
  125. for (j = ehdr->e_shnum; --j>=0; ++shdr) {
  126. if (key==(int)byteswap32_to_host(shdr->sh_type)) {
  127. return shdr;
  128. }
  129. }
  130. return NULL;
  131. }
  132. Elf32_Phdr * elf_find_phdr_type( int type, Elf32_Ehdr *ehdr)
  133. {
  134. int j;
  135. Elf32_Phdr *phdr = (Elf32_Phdr *)(ehdr->e_phoff + (char *)ehdr);
  136. for (j = ehdr->e_phnum; --j>=0; ++phdr) {
  137. if (type==(int)byteswap32_to_host(phdr->p_type)) {
  138. return phdr;
  139. }
  140. }
  141. return NULL;
  142. }
  143. /* Returns value if return_val==1, ptr otherwise */
  144. void * elf_find_dynamic(int const key, Elf32_Dyn *dynp,
  145. Elf32_Ehdr *ehdr, int return_val)
  146. {
  147. Elf32_Phdr *pt_text = elf_find_phdr_type(PT_LOAD, ehdr);
  148. unsigned tx_reloc = byteswap32_to_host(pt_text->p_vaddr) - byteswap32_to_host(pt_text->p_offset);
  149. for (; DT_NULL!=byteswap32_to_host(dynp->d_tag); ++dynp) {
  150. if (key == (int)byteswap32_to_host(dynp->d_tag)) {
  151. if (return_val == 1)
  152. return (void *)(intptr_t)byteswap32_to_host(dynp->d_un.d_val);
  153. else
  154. return (void *)(byteswap32_to_host(dynp->d_un.d_val) - tx_reloc + (char *)ehdr );
  155. }
  156. }
  157. return NULL;
  158. }
  159. static char * elf_find_rpath(Elf32_Ehdr* ehdr, Elf32_Dyn* dynamic)
  160. {
  161. Elf32_Dyn *dyns;
  162. for (dyns=dynamic; byteswap32_to_host(dyns->d_tag)!=DT_NULL; ++dyns) {
  163. if (DT_RPATH == byteswap32_to_host(dyns->d_tag)) {
  164. char *strtab;
  165. strtab = (char *)elf_find_dynamic(DT_STRTAB, dynamic, ehdr, 0);
  166. return ((char*)strtab + byteswap32_to_host(dyns->d_un.d_val));
  167. }
  168. }
  169. return NULL;
  170. }
  171. int check_elf_header(Elf32_Ehdr *const ehdr)
  172. {
  173. if (! ehdr || strncmp((void *)ehdr, ELFMAG, SELFMAG) != 0 ||
  174. ehdr->e_ident[EI_CLASS] != ELFCLASS32 ||
  175. ehdr->e_ident[EI_VERSION] != EV_CURRENT)
  176. {
  177. return 1;
  178. }
  179. /* Check if the target endianness matches the host's endianness */
  180. byteswap = 0;
  181. #if __BYTE_ORDER == __LITTLE_ENDIAN
  182. if (ehdr->e_ident[5] == ELFDATA2MSB) {
  183. /* Ick -- we will have to byte-swap everything */
  184. byteswap = 1;
  185. }
  186. #elif __BYTE_ORDER == __BIG_ENDIAN
  187. if (ehdr->e_ident[5] == ELFDATA2LSB) {
  188. /* Ick -- we will have to byte-swap everything */
  189. byteswap = 1;
  190. }
  191. #else
  192. #error Unknown host byte order!
  193. #endif
  194. /* Be vary lazy, and only byteswap the stuff we use */
  195. if (byteswap==1) {
  196. ehdr->e_type=bswap_16(ehdr->e_type);
  197. ehdr->e_phoff=bswap_32(ehdr->e_phoff);
  198. ehdr->e_shoff=bswap_32(ehdr->e_shoff);
  199. ehdr->e_phnum=bswap_16(ehdr->e_phnum);
  200. ehdr->e_shnum=bswap_16(ehdr->e_shnum);
  201. }
  202. return 0;
  203. }
  204. /* This function's behavior must exactly match that
  205. * in uClibc/ldso/ldso/dl-elf.c */
  206. static void search_for_named_library(char *name, char *result, const char *path_list)
  207. {
  208. int i, count = 1;
  209. char *path, *path_n;
  210. struct stat filestat;
  211. /* We need a writable copy of this string */
  212. path = strdup(path_list);
  213. if (!path) {
  214. fprintf(stderr, "Out of memory!\n");
  215. exit(EXIT_FAILURE);
  216. }
  217. /* Eliminate all double //s */
  218. path_n=path;
  219. while((path_n=strstr(path_n, "//"))) {
  220. i = strlen(path_n);
  221. memmove(path_n, path_n+1, i-1);
  222. *(path_n + i - 1)='\0';
  223. }
  224. /* Replace colons with zeros in path_list and count them */
  225. for(i=strlen(path); i > 0; i--) {
  226. if (path[i]==':') {
  227. path[i]=0;
  228. count++;
  229. }
  230. }
  231. path_n = path;
  232. for (i = 0; i < count; i++) {
  233. strcpy(result, path_n);
  234. strcat(result, "/");
  235. strcat(result, name);
  236. if (stat (result, &filestat) == 0 && filestat.st_mode & S_IRUSR) {
  237. free(path);
  238. return;
  239. }
  240. path_n += (strlen(path_n) + 1);
  241. }
  242. free(path);
  243. *result = '\0';
  244. }
  245. void locate_library_file(Elf32_Ehdr* ehdr, Elf32_Dyn* dynamic, int is_suid, struct library *lib)
  246. {
  247. char *buf;
  248. char *path;
  249. struct stat filestat;
  250. /* If this is a fully resolved name, our job is easy */
  251. if (stat (lib->name, &filestat) == 0) {
  252. lib->path = strdup(lib->name);
  253. return;
  254. }
  255. /* We need some elbow room here. Make some room...*/
  256. buf = malloc(1024);
  257. if (!buf) {
  258. fprintf(stderr, "Out of memory!\n");
  259. exit(EXIT_FAILURE);
  260. }
  261. /* This function must match the behavior of _dl_load_shared_library
  262. * in readelflib1.c or things won't work out as expected... */
  263. /* The ABI specifies that RPATH is searched first, so do that now. */
  264. path = elf_find_rpath(ehdr, dynamic);
  265. if (path) {
  266. search_for_named_library(lib->name, buf, path);
  267. if (*buf != '\0') {
  268. lib->path = buf;
  269. return;
  270. }
  271. }
  272. /* Next check LD_{ELF_}LIBRARY_PATH if specified and allowed.
  273. * Since this app doesn't actually run an executable I will skip
  274. * the suid check, and just use LD_{ELF_}LIBRARY_PATH if set */
  275. if (is_suid==1)
  276. path = NULL;
  277. else
  278. path = getenv("LD_LIBRARY_PATH");
  279. if (path) {
  280. search_for_named_library(lib->name, buf, path);
  281. if (*buf != '\0') {
  282. lib->path = buf;
  283. return;
  284. }
  285. }
  286. #ifdef USE_CACHE
  287. /* FIXME -- add code to check the Cache here */
  288. #endif
  289. /* Next look for libraries wherever the shared library
  290. * loader was installed -- this is usually where we
  291. * should find things... */
  292. if (interp_dir) {
  293. search_for_named_library(lib->name, buf, interp_dir);
  294. if (*buf != '\0') {
  295. lib->path = buf;
  296. return;
  297. }
  298. }
  299. /* Lastly, search the standard list of paths for the library.
  300. This list must exactly match the list in uClibc/ldso/ldso/dl-elf.c */
  301. path = UCLIBC_RUNTIME_PREFIX "usr/X11R6/lib:"
  302. UCLIBC_RUNTIME_PREFIX "usr/lib:"
  303. UCLIBC_RUNTIME_PREFIX "lib:"
  304. "/usr/X11R6/lib:"
  305. "/usr/lib:"
  306. "/lib";
  307. search_for_named_library(lib->name, buf, path);
  308. if (*buf != '\0') {
  309. lib->path = buf;
  310. } else {
  311. free(buf);
  312. lib->path = not_found;
  313. }
  314. }
  315. static int add_library(Elf32_Ehdr* ehdr, Elf32_Dyn* dynamic, int is_setuid, char *s)
  316. {
  317. char *tmp, *tmp1, *tmp2;
  318. struct library *cur, *newlib=lib_list;
  319. if (!s || !strlen(s))
  320. return 1;
  321. tmp = s;
  322. while (*tmp) {
  323. if (*tmp == '/')
  324. s = tmp + 1;
  325. tmp++;
  326. }
  327. /* We add ldso elsewhere */
  328. if (interpreter_already_found && (tmp=strrchr(interp, '/')) != NULL)
  329. {
  330. int len = strlen(interp_dir);
  331. if (strcmp(s, interp+1+len)==0)
  332. return 1;
  333. }
  334. for (cur = lib_list; cur; cur=cur->next) {
  335. /* Check if this library is already in the list */
  336. tmp1 = tmp2 = cur->name;
  337. while (*tmp1) {
  338. if (*tmp1 == '/')
  339. tmp2 = tmp1 + 1;
  340. tmp1++;
  341. }
  342. if(strcmp(tmp2, s)==0) {
  343. //printf("find_elf_interpreter is skipping '%s' (already in list)\n", cur->name);
  344. return 0;
  345. }
  346. }
  347. /* Ok, this lib needs to be added to the list */
  348. newlib = malloc(sizeof(struct library));
  349. if (!newlib)
  350. return 1;
  351. newlib->name = malloc(strlen(s)+1);
  352. strcpy(newlib->name, s);
  353. newlib->resolved = 0;
  354. newlib->path = NULL;
  355. newlib->next = NULL;
  356. /* Now try and locate where this library might be living... */
  357. locate_library_file(ehdr, dynamic, is_setuid, newlib);
  358. //printf("add_library is adding '%s' to '%s'\n", newlib->name, newlib->path);
  359. if (!lib_list) {
  360. lib_list = newlib;
  361. } else {
  362. for (cur = lib_list; cur->next; cur=cur->next); /* nothing */
  363. cur->next = newlib;
  364. }
  365. return 0;
  366. }
  367. static void find_needed_libraries(Elf32_Ehdr* ehdr,
  368. Elf32_Dyn* dynamic, int is_setuid)
  369. {
  370. Elf32_Dyn *dyns;
  371. for (dyns=dynamic; byteswap32_to_host(dyns->d_tag)!=DT_NULL; ++dyns) {
  372. if (DT_NEEDED == byteswap32_to_host(dyns->d_tag)) {
  373. char *strtab;
  374. strtab = (char *)elf_find_dynamic(DT_STRTAB, dynamic, ehdr, 0);
  375. add_library(ehdr, dynamic, is_setuid,
  376. (char*)strtab + byteswap32_to_host(dyns->d_un.d_val));
  377. }
  378. }
  379. }
  380. static struct library * find_elf_interpreter(Elf32_Ehdr* ehdr)
  381. {
  382. Elf32_Phdr *phdr;
  383. if (interpreter_already_found==1)
  384. return NULL;
  385. phdr = elf_find_phdr_type(PT_INTERP, ehdr);
  386. if (phdr) {
  387. struct library *cur, *newlib=NULL;
  388. char *s = (char*)ehdr + byteswap32_to_host(phdr->p_offset);
  389. char *tmp, *tmp1;
  390. interp = strdup(s);
  391. interp_dir = strdup(s);
  392. tmp = strrchr(interp_dir, '/');
  393. if (*tmp)
  394. *tmp = '\0';
  395. else {
  396. free(interp_dir);
  397. interp_dir = interp;
  398. }
  399. tmp1 = tmp = s;
  400. while (*tmp) {
  401. if (*tmp == '/')
  402. tmp1 = tmp + 1;
  403. tmp++;
  404. }
  405. for (cur = lib_list; cur; cur=cur->next) {
  406. /* Check if this library is already in the list */
  407. if(strcmp(cur->name, tmp1)==0) {
  408. //printf("find_elf_interpreter is replacing '%s' (already in list)\n", cur->name);
  409. newlib = cur;
  410. free(newlib->name);
  411. if (newlib->path != not_found) {
  412. free(newlib->path);
  413. }
  414. newlib->name = NULL;
  415. newlib->path = NULL;
  416. return NULL;
  417. }
  418. }
  419. if (newlib == NULL)
  420. newlib = malloc(sizeof(struct library));
  421. if (!newlib)
  422. return NULL;
  423. newlib->name = malloc(strlen(s)+1);
  424. strcpy(newlib->name, s);
  425. newlib->path = strdup(newlib->name);
  426. newlib->resolved = 1;
  427. newlib->next = NULL;
  428. #if 0
  429. //printf("find_elf_interpreter is adding '%s' to '%s'\n", newlib->name, newlib->path);
  430. if (!lib_list) {
  431. lib_list = newlib;
  432. } else {
  433. for (cur = lib_list; cur->next; cur=cur->next); /* nothing */
  434. cur->next = newlib;
  435. }
  436. #endif
  437. interpreter_already_found=1;
  438. return newlib;
  439. }
  440. return NULL;
  441. }
  442. /* map the .so, and locate interesting pieces */
  443. int find_dependancies(char* filename)
  444. {
  445. int is_suid = 0;
  446. FILE *thefile;
  447. struct stat statbuf;
  448. Elf32_Ehdr *ehdr = NULL;
  449. Elf32_Shdr *dynsec = NULL;
  450. Elf32_Dyn *dynamic = NULL;
  451. struct library *interp;
  452. if (filename == not_found)
  453. return 0;
  454. if (!filename) {
  455. fprintf(stderr, "No filename specified.\n");
  456. return -1;
  457. }
  458. if (!(thefile = fopen(filename, "r"))) {
  459. perror(filename);
  460. return -1;
  461. }
  462. if (fstat(fileno(thefile), &statbuf) < 0) {
  463. perror(filename);
  464. fclose(thefile);
  465. return -1;
  466. }
  467. if ((size_t)statbuf.st_size < sizeof(Elf32_Ehdr))
  468. goto foo;
  469. if (!S_ISREG(statbuf.st_mode))
  470. goto foo;
  471. /* mmap the file to make reading stuff from it effortless */
  472. ehdr = (Elf32_Ehdr *)mmap(0, statbuf.st_size,
  473. PROT_READ|PROT_WRITE, MAP_PRIVATE, fileno(thefile), 0);
  474. if (ehdr == MAP_FAILED) {
  475. fclose(thefile);
  476. fprintf(stderr, "Out of memory!\n");
  477. return -1;
  478. }
  479. foo:
  480. fclose(thefile);
  481. /* Check if this looks like a legit ELF file */
  482. if (check_elf_header(ehdr)) {
  483. fprintf(stderr, "%s: not an ELF file.\n", filename);
  484. return -1;
  485. }
  486. /* Check if this is the right kind of ELF file */
  487. if (ehdr->e_type != ET_EXEC && ehdr->e_type != ET_DYN) {
  488. fprintf(stderr, "%s: not a dynamic executable\n", filename);
  489. return -1;
  490. }
  491. if (ehdr->e_type == ET_EXEC) {
  492. if (statbuf.st_mode & S_ISUID)
  493. is_suid = 1;
  494. if ((statbuf.st_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
  495. is_suid = 1;
  496. /* FIXME */
  497. if (is_suid)
  498. fprintf(stderr, "%s: is setuid\n", filename);
  499. }
  500. interpreter_already_found=0;
  501. interp = find_elf_interpreter(ehdr);
  502. #ifdef __LDSO_LDD_SUPPORT
  503. if (interp && ehdr->e_type == ET_EXEC && ehdr->e_ident[EI_CLASS] == ELFCLASSM &&
  504. ehdr->e_ident[EI_DATA] == ELFDATAM
  505. && ehdr->e_ident[EI_VERSION] == EV_CURRENT && MATCH_MACHINE(ehdr->e_machine))
  506. {
  507. struct stat statbuf;
  508. if (stat(interp->path, &statbuf) == 0 && S_ISREG(statbuf.st_mode)) {
  509. pid_t pid;
  510. int status;
  511. static const char * const environment[] = {
  512. "PATH=/usr/bin:/bin:/usr/sbin:/sbin",
  513. "SHELL=/bin/sh",
  514. "LD_TRACE_LOADED_OBJECTS=1",
  515. NULL
  516. };
  517. if ((pid = fork()) == 0) {
  518. /* Cool, it looks like we should be able to actually
  519. * run this puppy. Do so now... */
  520. execle(filename, filename, NULL, environment);
  521. _exit(0xdead);
  522. }
  523. /* Wait till it returns */
  524. waitpid(pid, &status, 0);
  525. if (WIFEXITED(status) && WEXITSTATUS(status)==0) {
  526. return 1;
  527. }
  528. /* If the exec failed, we fall through to trying to find
  529. * all the needed libraries ourselves by rummaging about
  530. * in the ELF headers... */
  531. }
  532. }
  533. #endif
  534. dynsec = elf_find_section_type(SHT_DYNAMIC, ehdr);
  535. if (dynsec) {
  536. dynamic = (Elf32_Dyn*)(byteswap32_to_host(dynsec->sh_offset) + (intptr_t)ehdr);
  537. find_needed_libraries(ehdr, dynamic, is_suid);
  538. }
  539. return 0;
  540. }
  541. int main( int argc, char** argv)
  542. {
  543. int multi=0;
  544. int got_em_all=1;
  545. char *filename = NULL;
  546. struct library *cur;
  547. if (argc < 2) {
  548. fprintf(stderr, "ldd: missing file arguments\n");
  549. fprintf(stderr, "Try `ldd --help' for more information.\n");
  550. exit(EXIT_FAILURE);
  551. }
  552. if (argc > 2) {
  553. multi++;
  554. }
  555. while (--argc > 0) {
  556. ++argv;
  557. if(strcmp(*argv, "--")==0) {
  558. /* Ignore "--" */
  559. continue;
  560. }
  561. if(strcmp(*argv, "--help")==0) {
  562. fprintf(stderr, "Usage: ldd [OPTION]... FILE...\n");
  563. fprintf(stderr, "\t--help\t\tprint this help and exit\n");
  564. exit(EXIT_FAILURE);
  565. }
  566. filename=*argv;
  567. if (!filename) {
  568. fprintf(stderr, "No filename specified.\n");
  569. exit(EXIT_FAILURE);
  570. }
  571. if (multi) {
  572. printf("%s:\n", *argv);
  573. }
  574. if (find_dependancies(filename)!=0)
  575. continue;
  576. while(got_em_all) {
  577. got_em_all=0;
  578. /* Keep walking the list till everybody is resolved */
  579. for (cur = lib_list; cur; cur=cur->next) {
  580. if (cur->resolved == 0 && cur->path) {
  581. got_em_all=1;
  582. //printf("checking sub-depends for '%s\n", cur->path);
  583. find_dependancies(cur->path);
  584. cur->resolved = 1;
  585. }
  586. }
  587. }
  588. /* Print the list */
  589. got_em_all=0;
  590. for (cur = lib_list; cur; cur=cur->next) {
  591. got_em_all=1;
  592. printf("\t%s => %s (0x00000000)\n", cur->name, cur->path);
  593. }
  594. if (interp && interpreter_already_found==1)
  595. printf("\t%s => %s (0x00000000)\n", interp, interp);
  596. else
  597. printf("\tnot a dynamic executable\n");
  598. for (cur = lib_list; cur; cur=cur->next) {
  599. free(cur->name);
  600. cur->name=NULL;
  601. if (cur->path && cur->path != not_found) {
  602. free(cur->path);
  603. cur->path=NULL;
  604. }
  605. }
  606. lib_list=NULL;
  607. }
  608. return 0;
  609. }