dlib.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. /*
  2. * libdl.c
  3. *
  4. * Functions required for dlopen et. al.
  5. */
  6. #include "dlfcn.h"
  7. /* #include "link.h" */
  8. #include <stdlib.h>
  9. #include <linux/mman.h>
  10. #include <linux/unistd.h>
  11. #include "sysdep.h"
  12. #include "syscall.h"
  13. #include "hash.h"
  14. #include "string.h"
  15. #include "linuxelf.h"
  16. extern int _dl_error_number;
  17. extern struct r_debug * _dl_debug_addr;
  18. extern void * (*_dl_malloc_function)(size_t size);
  19. static int do_fixup(struct elf_resolve * tpnt, int flag);
  20. static int do_dlclose(void *, int need_fini);
  21. void * _dlopen(char * filename, int flag);
  22. const char * _dlerror(void);
  23. void * _dlsym(void *, char *);
  24. int _dlclose(void *);
  25. int _dladdr(void * __address, Dl_info * __dlip );
  26. static const char * dl_error_names[] = {
  27. "",
  28. "File not found",
  29. "Unable to open /dev/zero",
  30. "Not an ELF file",
  31. #if defined (__i386__)
  32. "Not i386 binary",
  33. #elif defined (__sparc__)
  34. "Not sparc binary",
  35. #elif defined (__mc68000__)
  36. "Not m68k binary",
  37. #else
  38. "Unrecognized binary type",
  39. #endif
  40. "Not an ELF shared library",
  41. "Unable to mmap file",
  42. "No dynamic section",
  43. #ifdef ELF_USES_RELOCA
  44. "Unable to process REL relocs",
  45. #else
  46. "Unable to process RELA relocs",
  47. #endif
  48. "Bad handle",
  49. "Unable to resolve symbol"
  50. };
  51. static void dl_cleanup(void) __attribute__ ((destructor));
  52. static void dl_cleanup(void)
  53. {
  54. struct dyn_elf* d;
  55. for (d = _dl_handles; d; d = d->next_handle)
  56. if (d->dyn->libtype == loaded_file && d->dyn->dynamic_info[DT_FINI])
  57. {
  58. (*((int(*)(void))(d->dyn->loadaddr + d->dyn->dynamic_info[DT_FINI])))();
  59. d->dyn->dynamic_info[DT_FINI] = 0;
  60. }
  61. }
  62. void * _dlopen(char * libname, int flag)
  63. {
  64. struct elf_resolve * tpnt, *tfrom;
  65. struct dyn_elf * rpnt;
  66. struct dyn_elf * dyn_chain;
  67. struct dyn_elf * dpnt;
  68. static int dl_init = 0;
  69. char * from;
  70. void (*dl_brk)(void);
  71. int (*dl_elf_init)(void);
  72. from = __builtin_return_address(0);
  73. /* Have the dynamic linker use the regular malloc function now */
  74. if (!dl_init) {
  75. dl_init++;
  76. _dl_malloc_function = malloc;
  77. }
  78. /* Cover the trivial case first */
  79. if (!libname) return _dl_symbol_tables;
  80. #ifdef USE_CACHE
  81. _dl_map_cache();
  82. #endif
  83. /*
  84. * Try and locate the module we were called from - we
  85. * need this so that we get the correct RPATH. Note that
  86. * this is the current behavior under Solaris, but the
  87. * ABI+ specifies that we should only use the RPATH from
  88. * the application. Thus this may go away at some time
  89. * in the future.
  90. */
  91. tfrom = NULL;
  92. for(dpnt = _dl_symbol_tables; dpnt; dpnt = dpnt->next)
  93. {
  94. tpnt = dpnt->dyn;
  95. if( tpnt->loadaddr < from
  96. && ( tfrom == NULL
  97. || tfrom->loadaddr < tpnt->loadaddr))
  98. tfrom = tpnt;
  99. }
  100. if(!(tpnt = _dl_load_shared_library(0, tfrom, libname)))
  101. {
  102. #ifdef USE_CACHE
  103. _dl_unmap_cache();
  104. #endif
  105. return NULL;
  106. }
  107. tpnt->usage_count++;
  108. dyn_chain = rpnt =
  109. (struct dyn_elf *) malloc(sizeof(struct dyn_elf));
  110. _dl_memset (rpnt, 0, sizeof(*rpnt));
  111. rpnt->dyn = tpnt;
  112. rpnt->flags = flag;
  113. if (!tpnt->symbol_scope) tpnt->symbol_scope = dyn_chain;
  114. rpnt->next_handle = _dl_handles;
  115. _dl_handles = rpnt;
  116. /*
  117. * OK, we have the requested file in memory. Now check for
  118. * any other requested files that may also be required.
  119. */
  120. {
  121. struct elf_resolve *tcurr;
  122. struct elf_resolve * tpnt1;
  123. struct dynamic * dpnt;
  124. char * lpnt;
  125. tcurr = tpnt;
  126. do{
  127. for(dpnt = (struct dynamic *) tcurr->dynamic_addr; dpnt->d_tag; dpnt++)
  128. {
  129. if(dpnt->d_tag == DT_NEEDED)
  130. {
  131. lpnt = tcurr->loadaddr + tcurr->dynamic_info[DT_STRTAB] +
  132. dpnt->d_un.d_val;
  133. if(!(tpnt1 = _dl_load_shared_library(0, tcurr, lpnt)))
  134. goto oops;
  135. rpnt->next =
  136. (struct dyn_elf *) malloc(sizeof(struct dyn_elf));
  137. _dl_memset (rpnt->next, 0, sizeof (*(rpnt->next)));
  138. rpnt = rpnt->next;
  139. tpnt1->usage_count++;
  140. if (!tpnt1->symbol_scope) tpnt1->symbol_scope = dyn_chain;
  141. rpnt->dyn = tpnt1;
  142. };
  143. }
  144. tcurr = tcurr->next;
  145. } while(tcurr);
  146. }
  147. /*
  148. * OK, now attach the entire chain at the end
  149. */
  150. rpnt->next = _dl_symbol_tables;
  151. if (do_fixup(tpnt, flag)) {
  152. _dl_error_number = DL_NO_SYMBOL;
  153. goto oops;
  154. }
  155. dl_brk = (void (*)()) _dl_debug_addr->r_brk;
  156. if( dl_brk != NULL )
  157. {
  158. _dl_debug_addr->r_state = RT_ADD;
  159. (*dl_brk)();
  160. _dl_debug_addr->r_state = RT_CONSISTENT;
  161. (*dl_brk)();
  162. }
  163. for(rpnt = dyn_chain; rpnt; rpnt = rpnt->next)
  164. {
  165. tpnt = rpnt->dyn;
  166. /* Apparently crt1 for the application is responsible for handling this.
  167. * We only need to run the init/fini for shared libraries
  168. */
  169. if (tpnt->libtype == elf_executable) continue;
  170. if (tpnt->init_flag & INIT_FUNCS_CALLED) continue;
  171. tpnt->init_flag |= INIT_FUNCS_CALLED;
  172. if(tpnt->dynamic_info[DT_INIT]) {
  173. dl_elf_init = (int (*)(void)) (tpnt->loadaddr +
  174. tpnt->dynamic_info[DT_INIT]);
  175. (*dl_elf_init)();
  176. }
  177. }
  178. #ifdef USE_CACHE
  179. _dl_unmap_cache();
  180. #endif
  181. return (void *) dyn_chain;
  182. oops:
  183. /* Something went wrong. Clean up and return NULL. */
  184. #ifdef USE_CACHE
  185. _dl_unmap_cache();
  186. #endif
  187. do_dlclose (dyn_chain, 0);
  188. return NULL;
  189. }
  190. static int do_fixup(struct elf_resolve * tpnt, int flag)
  191. {
  192. int goof = 0;
  193. if(tpnt->next) goof += do_fixup(tpnt->next, flag);
  194. if(tpnt->dynamic_info[DT_REL]) {
  195. #ifdef ELF_USES_RELOCA
  196. goof++;
  197. #else
  198. if (tpnt->init_flag & RELOCS_DONE) return goof;
  199. tpnt->init_flag |= RELOCS_DONE;
  200. goof += _dl_parse_relocation_information(tpnt, tpnt->dynamic_info[DT_REL],
  201. tpnt->dynamic_info[DT_RELSZ], 0);
  202. #endif
  203. }
  204. if(tpnt->dynamic_info[DT_RELA]) {
  205. #ifdef ELF_USES_RELOCA
  206. if (tpnt->init_flag & RELOCS_DONE) return goof;
  207. tpnt->init_flag |= RELOCS_DONE;
  208. goof += _dl_parse_relocation_information(tpnt, tpnt->dynamic_info[DT_RELA],
  209. tpnt->dynamic_info[DT_RELASZ], 0);
  210. #else
  211. goof++;
  212. #endif
  213. }
  214. if(tpnt->dynamic_info[DT_JMPREL])
  215. {
  216. if (tpnt->init_flag & JMP_RELOCS_DONE) return goof;
  217. tpnt->init_flag |= JMP_RELOCS_DONE;
  218. if(flag == RTLD_LAZY)
  219. _dl_parse_lazy_relocation_information(tpnt, tpnt->dynamic_info[DT_JMPREL],
  220. tpnt->dynamic_info[DT_PLTRELSZ], 0);
  221. else
  222. goof += _dl_parse_relocation_information(tpnt,
  223. tpnt->dynamic_info[DT_JMPREL],
  224. tpnt->dynamic_info[DT_PLTRELSZ], 0);
  225. };
  226. return goof;
  227. }
  228. void * _dlsym(void * vhandle, char * name)
  229. {
  230. struct elf_resolve * tpnt, *tfrom;
  231. struct dyn_elf * handle;
  232. char * from;
  233. struct dyn_elf * rpnt;
  234. void *ret;
  235. handle = (struct dyn_elf *) vhandle;
  236. /* First of all verify that we have a real handle
  237. of some kind. Return NULL if not a valid handle. */
  238. if (handle == NULL)
  239. handle = _dl_symbol_tables;
  240. else if (handle != RTLD_NEXT && handle != _dl_symbol_tables) {
  241. for(rpnt = _dl_handles; rpnt; rpnt = rpnt->next_handle)
  242. if (rpnt == handle) break;
  243. if (!rpnt) {
  244. _dl_error_number = DL_BAD_HANDLE;
  245. return NULL;
  246. }
  247. }
  248. else if (handle == RTLD_NEXT )
  249. {
  250. /*
  251. * Try and locate the module we were called from - we
  252. * need this so that we know where to start searching
  253. * from. We never pass RTLD_NEXT down into the actual
  254. * dynamic loader itself, as it doesn't know
  255. * how to properly treat it.
  256. */
  257. from = __builtin_return_address(0);
  258. tfrom = NULL;
  259. for(rpnt = _dl_symbol_tables; rpnt; rpnt = rpnt->next)
  260. {
  261. tpnt = rpnt->dyn;
  262. if( tpnt->loadaddr < from
  263. && ( tfrom == NULL
  264. || tfrom->loadaddr < tpnt->loadaddr))
  265. {
  266. tfrom = tpnt;
  267. handle = rpnt->next;
  268. }
  269. }
  270. }
  271. ret = _dl_find_hash(name, handle, 1, NULL, 1);
  272. /*
  273. * Nothing found.
  274. */
  275. if (!ret)
  276. _dl_error_number = DL_NO_SYMBOL;
  277. return ret;
  278. }
  279. int _dlclose(void * vhandle)
  280. {
  281. return do_dlclose(vhandle, 1);
  282. }
  283. static int do_dlclose(void * vhandle, int need_fini)
  284. {
  285. struct dyn_elf * rpnt, *rpnt1;
  286. struct dyn_elf *spnt, *spnt1;
  287. struct elf_phdr * ppnt;
  288. struct elf_resolve * tpnt;
  289. int (*dl_elf_fini)(void);
  290. void (*dl_brk)(void);
  291. struct dyn_elf * handle;
  292. unsigned int end;
  293. int i = 0;
  294. handle = (struct dyn_elf *) vhandle;
  295. rpnt1 = NULL;
  296. for(rpnt = _dl_handles; rpnt; rpnt = rpnt->next_handle)
  297. {
  298. if(rpnt == handle) {
  299. break;
  300. }
  301. rpnt1 = rpnt;
  302. }
  303. if (!rpnt) {
  304. _dl_error_number = DL_BAD_HANDLE;
  305. return 1;
  306. }
  307. /* OK, this is a valid handle - now close out the file.
  308. * We check if we need to call fini () on the handle. */
  309. spnt = need_fini ? handle : handle->next;
  310. for(; spnt; spnt = spnt1)
  311. {
  312. spnt1 = spnt->next;
  313. /* We appended the module list to the end - when we get back here,
  314. quit. The access counts were not adjusted to account for being here. */
  315. if (spnt == _dl_symbol_tables) break;
  316. if(spnt->dyn->usage_count==1 && spnt->dyn->libtype == loaded_file) {
  317. tpnt = spnt->dyn;
  318. /* Apparently crt1 for the application is responsible for handling this.
  319. * We only need to run the init/fini for shared libraries
  320. */
  321. if(tpnt->dynamic_info[DT_FINI]) {
  322. dl_elf_fini = (int (*)(void)) (tpnt->loadaddr +
  323. tpnt->dynamic_info[DT_FINI]);
  324. (*dl_elf_fini)();
  325. }
  326. }
  327. }
  328. if(rpnt1)
  329. rpnt1->next_handle = rpnt->next_handle;
  330. else
  331. _dl_handles = rpnt->next_handle;
  332. /* OK, this is a valid handle - now close out the file */
  333. for(rpnt = handle; rpnt; rpnt = rpnt1)
  334. {
  335. rpnt1 = rpnt->next;
  336. /* We appended the module list to the end - when we get back here,
  337. quit. The access counts were not adjusted to account for being here. */
  338. if (rpnt == _dl_symbol_tables) break;
  339. rpnt->dyn->usage_count--;
  340. if(rpnt->dyn->usage_count == 0 && rpnt->dyn->libtype == loaded_file)
  341. {
  342. tpnt = rpnt->dyn;
  343. /* Apparently crt1 for the application is responsible for handling this.
  344. * We only need to run the init/fini for shared libraries
  345. */
  346. #if 0
  347. /* We have to do this above, before we start closing objects.
  348. Otherwise when the needed symbols for _fini handling are
  349. resolved a coredump would occur. Rob Ryan (robr@cmu.edu)*/
  350. if(tpnt->dynamic_info[DT_FINI]) {
  351. dl_elf_fini = (int (*)(void)) (tpnt->loadaddr +
  352. tpnt->dynamic_info[DT_FINI]);
  353. (*dl_elf_fini)();
  354. }
  355. #endif
  356. end = 0;
  357. for(i = 0, ppnt = rpnt->dyn->ppnt;
  358. i < rpnt->dyn->n_phent; ppnt++, i++) {
  359. if (ppnt->p_type != PT_LOAD) continue;
  360. if (end < ppnt->p_vaddr + ppnt->p_memsz)
  361. end = ppnt->p_vaddr + ppnt->p_memsz;
  362. }
  363. _dl_munmap (rpnt->dyn->loadaddr, end);
  364. /* Next, remove rpnt->dyn from the loaded_module list */
  365. if (_dl_loaded_modules == rpnt->dyn)
  366. {
  367. _dl_loaded_modules = rpnt->dyn->next;
  368. if (_dl_loaded_modules)
  369. _dl_loaded_modules->prev = 0;
  370. }
  371. else
  372. for (tpnt = _dl_loaded_modules; tpnt; tpnt = tpnt->next)
  373. if (tpnt->next == rpnt->dyn) {
  374. tpnt->next = tpnt->next->next;
  375. if (tpnt->next)
  376. tpnt->next->prev = tpnt;
  377. break;
  378. }
  379. free(rpnt->dyn->libname);
  380. free(rpnt->dyn);
  381. }
  382. free(rpnt);
  383. }
  384. dl_brk = (void (*)()) _dl_debug_addr->r_brk;
  385. if( dl_brk != NULL )
  386. {
  387. _dl_debug_addr->r_state = RT_DELETE;
  388. (*dl_brk)();
  389. _dl_debug_addr->r_state = RT_CONSISTENT;
  390. (*dl_brk)();
  391. }
  392. return 0;
  393. }
  394. const char * _dlerror()
  395. {
  396. const char * retval;
  397. if(!_dl_error_number) return NULL;
  398. retval = dl_error_names[_dl_error_number];
  399. _dl_error_number = 0;
  400. return retval;
  401. }
  402. /* Generate the correct symbols that we need. */
  403. #if 1
  404. #pragma weak dlopen = _dlopen
  405. #pragma weak dlerror = _dlerror
  406. #pragma weak dlclose = _dlclose
  407. #pragma weak dlsym = _dlsym
  408. #pragma weak dladdr = _dladdr
  409. #else
  410. __asm__(".weak dlopen;dlopen=_dlopen");
  411. __asm__(".weak dlerror;dlerror=_dlerror");
  412. __asm__(".weak dlclose;dlclose=_dlclose");
  413. __asm__(".weak dlsym;dlsym=_dlsym");
  414. __asm__(".weak dladdr;dladdr=_dladdr");
  415. #endif
  416. /* This is a real hack. We need access to the dynamic linker, but we
  417. also need to make it possible to link against this library without any
  418. unresolved externals. We provide these weak symbols to make the link
  419. possible, but at run time the normal symbols are accessed. */
  420. static void foobar()
  421. {
  422. _dl_fdprintf(2,"libdl library not correctly linked\n");
  423. _dl_exit(1);
  424. }
  425. static int __attribute__((unused)) foobar1 = (int)foobar; /* Use as pointer */
  426. #if 1
  427. #pragma weak _dl_find_hash = foobar
  428. #pragma weak _dl_symbol_tables = foobar1
  429. #pragma weak _dl_handles = foobar1
  430. #pragma weak _dl_loaded_modules = foobar1
  431. #pragma weak _dl_debug_addr = foobar1
  432. #pragma weak _dl_error_number = foobar1
  433. #pragma weak _dl_load_shared_library = foobar
  434. #ifdef USE_CACHE
  435. #pragma weak _dl_map_cache = foobar
  436. #pragma weak _dl_unmap_cache = foobar
  437. #endif
  438. #pragma weak _dl_malloc_function = foobar1
  439. #pragma weak _dl_parse_relocation_information = foobar
  440. #pragma weak _dl_parse_lazy_relocation_information = foobar
  441. #pragma weak _dl_fdprintf = foobar
  442. #else
  443. __asm__(".weak _dl_find_hash; _dl_find_hash = foobar");
  444. __asm__(".weak _dl_symbol_tables; _dl_symbol_tables = foobar1");
  445. __asm__(".weak _dl_handles; _dl_handles = foobar1");
  446. __asm__(".weak _dl_loaded_modules; _dl_loaded_modules = foobar1");
  447. __asm__(".weak _dl_debug_addr; _dl_debug_addr = foobar1");
  448. __asm__(".weak _dl_error_number; _dl_error_number = foobar1");
  449. __asm__(".weak _dl_load_shared_library; _dl_load_shared_library = foobar");
  450. #ifdef USE_CACHE
  451. __asm__(".weak _dl_map_cache; _dl_map_cache = foobar");
  452. __asm__(".weak _dl_unmap_cache; _dl_unmap_cache = foobar");
  453. #endif
  454. __asm__(".weak _dl_malloc_function; _dl_malloc_function = foobar1");
  455. __asm__(".weak _dl_parse_relocation_information; _dl_parse_relocation_information = foobar");
  456. __asm__(".weak _dl_parse_lazy_relocation_information; _dl_parse_lazy_relocation_information = foobar");
  457. __asm__(".weak _dl_fdprintf; _dl_fdprintf = foobar");
  458. #endif
  459. /*
  460. * Dump information to stderrr about the current loaded modules
  461. */
  462. static char * type[] = {"Lib","Exe","Int","Mod"};
  463. void _dlinfo()
  464. {
  465. struct elf_resolve * tpnt;
  466. struct dyn_elf * rpnt, *hpnt;
  467. _dl_fdprintf(2, "List of loaded modules\n");
  468. /* First start with a complete list of all of the loaded files. */
  469. for (tpnt = _dl_loaded_modules; tpnt; tpnt = tpnt->next)
  470. _dl_fdprintf(2, "\t%8.8x %8.8x %8.8x %s %d %s\n",
  471. (unsigned)tpnt->loadaddr, (unsigned)tpnt,
  472. (unsigned)tpnt->symbol_scope,
  473. type[tpnt->libtype],
  474. tpnt->usage_count,
  475. tpnt->libname);
  476. /* Next dump the module list for the application itself */
  477. _dl_fdprintf(2, "\nModules for application (%x):\n",
  478. (unsigned)_dl_symbol_tables);
  479. for (rpnt = _dl_symbol_tables; rpnt; rpnt = rpnt->next)
  480. _dl_fdprintf(2, "\t%8.8x %s\n", (unsigned)rpnt->dyn,
  481. rpnt->dyn->libname);
  482. for (hpnt = _dl_handles; hpnt; hpnt = hpnt->next_handle)
  483. {
  484. _dl_fdprintf(2, "Modules for handle %x\n", (unsigned)hpnt);
  485. for(rpnt = hpnt; rpnt; rpnt = rpnt->next)
  486. _dl_fdprintf(2, "\t%8.8x %s\n", (unsigned)rpnt->dyn,
  487. rpnt->dyn->libname);
  488. }
  489. }
  490. int _dladdr(void * __address, Dl_info * __dlip )
  491. {
  492. struct elf_resolve * pelf;
  493. struct elf_resolve * rpnt;
  494. #ifdef USE_CACHE
  495. _dl_map_cache();
  496. #endif
  497. /*
  498. * Try and locate the module address is in
  499. */
  500. pelf = NULL;
  501. #if 0
  502. _dl_fdprintf( 2,
  503. "dladdr( 0x%p, 0x%p )\n",
  504. __address, __dlip );
  505. #endif
  506. for(rpnt = _dl_loaded_modules; rpnt; rpnt = rpnt->next)
  507. {
  508. struct elf_resolve * tpnt;
  509. tpnt = rpnt;
  510. #if 0
  511. _dl_fdprintf( 2,
  512. "Module \"%s\" at 0x%p\n",
  513. tpnt->libname,
  514. tpnt->loadaddr );
  515. #endif
  516. if( tpnt->loadaddr < (char*)__address
  517. && ( pelf == NULL
  518. || pelf->loadaddr < tpnt->loadaddr))
  519. pelf = tpnt;
  520. }
  521. if ( ! pelf )
  522. {
  523. return 0;
  524. }
  525. /*
  526. * Try and locate the symbol of address
  527. */
  528. {
  529. char * strtab;
  530. struct elf32_sym * symtab;
  531. int hn, si;
  532. int sf;
  533. int sn = 0;
  534. void* sa = 0;
  535. symtab = (struct elf32_sym *) (pelf->dynamic_info[DT_SYMTAB] +
  536. pelf->loadaddr);
  537. strtab = (char *) (pelf->dynamic_info[DT_STRTAB] + pelf->loadaddr);
  538. sf = 0;
  539. for(hn = 0; hn < pelf->nbucket; hn++)
  540. {
  541. for(si = pelf->elf_buckets[hn]; si; si = pelf->chains[si])
  542. {
  543. void* symbol_addr;
  544. symbol_addr = pelf->loadaddr + symtab[si].st_value;
  545. if ( symbol_addr <= __address &&
  546. ( !sf || sa < symbol_addr ) )
  547. {
  548. sa = symbol_addr;
  549. sn = si;
  550. sf = 1;
  551. }
  552. #if 0
  553. _dl_fdprintf( 2,
  554. "Symbol \"%s\" at 0x%p\n",
  555. strtab + symtab[si].st_name,
  556. symbol_addr );
  557. #endif
  558. }
  559. }
  560. if ( sf )
  561. {
  562. __dlip->dli_fname = pelf->libname;
  563. __dlip->dli_fbase = pelf->loadaddr;
  564. __dlip->dli_sname = strtab + symtab[sn].st_name;
  565. __dlip->dli_saddr = sa;
  566. }
  567. return 1;
  568. }
  569. }