ldd.c 16 KB

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