ldd.c 16 KB

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