dlib.c 16 KB

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