ldd.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  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 "lib:"
  302. UCLIBC_RUNTIME_PREFIX "usr/lib";
  303. search_for_named_library(lib->name, buf, path);
  304. if (*buf != '\0') {
  305. lib->path = buf;
  306. } else {
  307. free(buf);
  308. lib->path = not_found;
  309. }
  310. }
  311. static int add_library(Elf32_Ehdr* ehdr, Elf32_Dyn* dynamic, int is_setuid, char *s)
  312. {
  313. char *tmp, *tmp1, *tmp2;
  314. struct library *cur, *newlib=lib_list;
  315. if (!s || !strlen(s))
  316. return 1;
  317. tmp = s;
  318. while (*tmp) {
  319. if (*tmp == '/')
  320. s = tmp + 1;
  321. tmp++;
  322. }
  323. /* We add ldso elsewhere */
  324. if (interpreter_already_found && (tmp=strrchr(interp, '/')) != NULL)
  325. {
  326. int len = strlen(interp_dir);
  327. if (strcmp(s, interp+1+len)==0)
  328. return 1;
  329. }
  330. for (cur = lib_list; cur; cur=cur->next) {
  331. /* Check if this library is already in the list */
  332. tmp1 = tmp2 = cur->name;
  333. while (*tmp1) {
  334. if (*tmp1 == '/')
  335. tmp2 = tmp1 + 1;
  336. tmp1++;
  337. }
  338. if(strcmp(tmp2, s)==0) {
  339. //printf("find_elf_interpreter is skipping '%s' (already in list)\n", cur->name);
  340. return 0;
  341. }
  342. }
  343. /* Ok, this lib needs to be added to the list */
  344. newlib = malloc(sizeof(struct library));
  345. if (!newlib)
  346. return 1;
  347. newlib->name = malloc(strlen(s)+1);
  348. strcpy(newlib->name, s);
  349. newlib->resolved = 0;
  350. newlib->path = NULL;
  351. newlib->next = NULL;
  352. /* Now try and locate where this library might be living... */
  353. locate_library_file(ehdr, dynamic, is_setuid, newlib);
  354. //printf("add_library is adding '%s' to '%s'\n", newlib->name, newlib->path);
  355. if (!lib_list) {
  356. lib_list = newlib;
  357. } else {
  358. for (cur = lib_list; cur->next; cur=cur->next); /* nothing */
  359. cur->next = newlib;
  360. }
  361. return 0;
  362. }
  363. static void find_needed_libraries(Elf32_Ehdr* ehdr,
  364. Elf32_Dyn* dynamic, int is_setuid)
  365. {
  366. Elf32_Dyn *dyns;
  367. for (dyns=dynamic; byteswap32_to_host(dyns->d_tag)!=DT_NULL; ++dyns) {
  368. if (DT_NEEDED == byteswap32_to_host(dyns->d_tag)) {
  369. char *strtab;
  370. strtab = (char *)elf_find_dynamic(DT_STRTAB, dynamic, ehdr, 0);
  371. add_library(ehdr, dynamic, is_setuid,
  372. (char*)strtab + byteswap32_to_host(dyns->d_un.d_val));
  373. }
  374. }
  375. }
  376. static struct library * find_elf_interpreter(Elf32_Ehdr* ehdr)
  377. {
  378. Elf32_Phdr *phdr;
  379. if (interpreter_already_found==1)
  380. return NULL;
  381. phdr = elf_find_phdr_type(PT_INTERP, ehdr);
  382. if (phdr) {
  383. struct library *cur, *newlib=NULL;
  384. char *s = (char*)ehdr + byteswap32_to_host(phdr->p_offset);
  385. char *tmp, *tmp1;
  386. interp = strdup(s);
  387. interp_dir = strdup(s);
  388. tmp = strrchr(interp_dir, '/');
  389. if (*tmp)
  390. *tmp = '\0';
  391. else {
  392. free(interp_dir);
  393. interp_dir = interp;
  394. }
  395. tmp1 = tmp = s;
  396. while (*tmp) {
  397. if (*tmp == '/')
  398. tmp1 = tmp + 1;
  399. tmp++;
  400. }
  401. for (cur = lib_list; cur; cur=cur->next) {
  402. /* Check if this library is already in the list */
  403. if(strcmp(cur->name, tmp1)==0) {
  404. //printf("find_elf_interpreter is replacing '%s' (already in list)\n", cur->name);
  405. newlib = cur;
  406. free(newlib->name);
  407. if (newlib->path != not_found) {
  408. free(newlib->path);
  409. }
  410. newlib->name = NULL;
  411. newlib->path = NULL;
  412. return NULL;
  413. }
  414. }
  415. if (newlib == NULL)
  416. newlib = malloc(sizeof(struct library));
  417. if (!newlib)
  418. return NULL;
  419. newlib->name = malloc(strlen(s)+1);
  420. strcpy(newlib->name, s);
  421. newlib->path = strdup(newlib->name);
  422. newlib->resolved = 1;
  423. newlib->next = NULL;
  424. #if 0
  425. //printf("find_elf_interpreter is adding '%s' to '%s'\n", newlib->name, newlib->path);
  426. if (!lib_list) {
  427. lib_list = newlib;
  428. } else {
  429. for (cur = lib_list; cur->next; cur=cur->next); /* nothing */
  430. cur->next = newlib;
  431. }
  432. #endif
  433. interpreter_already_found=1;
  434. return newlib;
  435. }
  436. return NULL;
  437. }
  438. /* map the .so, and locate interesting pieces */
  439. int find_dependancies(char* filename)
  440. {
  441. int is_suid = 0;
  442. FILE *thefile;
  443. struct stat statbuf;
  444. Elf32_Ehdr *ehdr = NULL;
  445. Elf32_Shdr *dynsec = NULL;
  446. Elf32_Dyn *dynamic = NULL;
  447. struct library *interp;
  448. if (filename == not_found)
  449. return 0;
  450. if (!filename) {
  451. fprintf(stderr, "No filename specified.\n");
  452. return -1;
  453. }
  454. if (!(thefile = fopen(filename, "r"))) {
  455. perror(filename);
  456. return -1;
  457. }
  458. if (fstat(fileno(thefile), &statbuf) < 0) {
  459. perror(filename);
  460. fclose(thefile);
  461. return -1;
  462. }
  463. if ((size_t)statbuf.st_size < sizeof(Elf32_Ehdr))
  464. goto foo;
  465. if (!S_ISREG(statbuf.st_mode))
  466. goto foo;
  467. /* mmap the file to make reading stuff from it effortless */
  468. ehdr = (Elf32_Ehdr *)mmap(0, statbuf.st_size,
  469. PROT_READ|PROT_WRITE, MAP_PRIVATE, fileno(thefile), 0);
  470. if (ehdr == MAP_FAILED) {
  471. fclose(thefile);
  472. fprintf(stderr, "Out of memory!\n");
  473. return -1;
  474. }
  475. foo:
  476. fclose(thefile);
  477. /* Check if this looks like a legit ELF file */
  478. if (check_elf_header(ehdr)) {
  479. fprintf(stderr, "%s: not an ELF file.\n", filename);
  480. return -1;
  481. }
  482. /* Check if this is the right kind of ELF file */
  483. if (ehdr->e_type != ET_EXEC && ehdr->e_type != ET_DYN) {
  484. fprintf(stderr, "%s: not a dynamic executable\n", filename);
  485. return -1;
  486. }
  487. if (ehdr->e_type == ET_EXEC || ehdr->e_type == ET_DYN) {
  488. if (statbuf.st_mode & S_ISUID)
  489. is_suid = 1;
  490. if ((statbuf.st_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
  491. is_suid = 1;
  492. /* FIXME */
  493. if (is_suid)
  494. fprintf(stderr, "%s: is setuid\n", filename);
  495. }
  496. interpreter_already_found=0;
  497. interp = find_elf_interpreter(ehdr);
  498. #ifdef __LDSO_LDD_SUPPORT
  499. if (interp && (ehdr->e_type == ET_EXEC || ehdr->e_type == ET_DYN) && ehdr->e_ident[EI_CLASS] == ELFCLASSM &&
  500. ehdr->e_ident[EI_DATA] == ELFDATAM
  501. && ehdr->e_ident[EI_VERSION] == EV_CURRENT && MATCH_MACHINE(ehdr->e_machine))
  502. {
  503. struct stat statbuf;
  504. if (stat(interp->path, &statbuf) == 0 && S_ISREG(statbuf.st_mode)) {
  505. pid_t pid;
  506. int status;
  507. static const char * const environment[] = {
  508. "PATH=/usr/bin:/bin:/usr/sbin:/sbin",
  509. "SHELL=/bin/sh",
  510. "LD_TRACE_LOADED_OBJECTS=1",
  511. NULL
  512. };
  513. if ((pid = fork()) == 0) {
  514. /* Cool, it looks like we should be able to actually
  515. * run this puppy. Do so now... */
  516. execle(filename, filename, NULL, environment);
  517. _exit(0xdead);
  518. }
  519. /* Wait till it returns */
  520. waitpid(pid, &status, 0);
  521. if (WIFEXITED(status) && WEXITSTATUS(status)==0) {
  522. return 1;
  523. }
  524. /* If the exec failed, we fall through to trying to find
  525. * all the needed libraries ourselves by rummaging about
  526. * in the ELF headers... */
  527. }
  528. }
  529. #endif
  530. dynsec = elf_find_section_type(SHT_DYNAMIC, ehdr);
  531. if (dynsec) {
  532. dynamic = (Elf32_Dyn*)(byteswap32_to_host(dynsec->sh_offset) + (intptr_t)ehdr);
  533. find_needed_libraries(ehdr, dynamic, is_suid);
  534. }
  535. return 0;
  536. }
  537. int main( int argc, char** argv)
  538. {
  539. int multi=0;
  540. int got_em_all=1;
  541. char *filename = NULL;
  542. struct library *cur;
  543. if (argc < 2) {
  544. fprintf(stderr, "ldd: missing file arguments\n");
  545. fprintf(stderr, "Try `ldd --help' for more information.\n");
  546. exit(EXIT_FAILURE);
  547. }
  548. if (argc > 2) {
  549. multi++;
  550. }
  551. while (--argc > 0) {
  552. ++argv;
  553. if(strcmp(*argv, "--")==0) {
  554. /* Ignore "--" */
  555. continue;
  556. }
  557. if(strcmp(*argv, "--help")==0) {
  558. fprintf(stderr, "Usage: ldd [OPTION]... FILE...\n");
  559. fprintf(stderr, "\t--help\t\tprint this help and exit\n");
  560. exit(EXIT_FAILURE);
  561. }
  562. filename=*argv;
  563. if (!filename) {
  564. fprintf(stderr, "No filename specified.\n");
  565. exit(EXIT_FAILURE);
  566. }
  567. if (multi) {
  568. printf("%s:\n", *argv);
  569. }
  570. if (find_dependancies(filename)!=0)
  571. continue;
  572. while(got_em_all) {
  573. got_em_all=0;
  574. /* Keep walking the list till everybody is resolved */
  575. for (cur = lib_list; cur; cur=cur->next) {
  576. if (cur->resolved == 0 && cur->path) {
  577. got_em_all=1;
  578. //printf("checking sub-depends for '%s\n", cur->path);
  579. find_dependancies(cur->path);
  580. cur->resolved = 1;
  581. }
  582. }
  583. }
  584. /* Print the list */
  585. got_em_all=0;
  586. for (cur = lib_list; cur; cur=cur->next) {
  587. got_em_all=1;
  588. printf("\t%s => %s (0x00000000)\n", cur->name, cur->path);
  589. }
  590. if (interp && interpreter_already_found==1)
  591. printf("\t%s => %s (0x00000000)\n", interp, interp);
  592. else
  593. printf("\tnot a dynamic executable\n");
  594. for (cur = lib_list; cur; cur=cur->next) {
  595. free(cur->name);
  596. cur->name=NULL;
  597. if (cur->path && cur->path != not_found) {
  598. free(cur->path);
  599. cur->path=NULL;
  600. }
  601. }
  602. lib_list=NULL;
  603. }
  604. return 0;
  605. }