1 /* vi: set sw=4 ts=4: */
3 * Program to load an ELF binary on a linux system, and run it
4 * after resolving ELF shared library symbols
6 * Copyright (C) 2000-2006 by Erik Andersen <andersen@uclibc.org>
7 * Copyright (c) 1994-2000 Eric Youngdale, Peter MacDonald,
8 * David Engel, Hongjiu Lu and Mitch D'Souza
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. The name of the above contributors may not be
16 * used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <string.h> /* Needed for 'strstr' prototype' */
41 /* When libdl is loaded as a shared library, we need to load in
42 * and use a pile of symbols from ldso... */
44 extern char *_dl_find_hash(const char *, struct dyn_elf *, struct elf_resolve *, int);
45 extern struct elf_resolve * _dl_load_shared_library(int, struct dyn_elf **,
46 struct elf_resolve *, char *, int);
47 extern int _dl_fixup(struct dyn_elf *rpnt, int lazy);
48 extern void _dl_protect_relro(struct elf_resolve * tpnt);
50 extern struct dyn_elf *_dl_symbol_tables;
51 extern struct dyn_elf *_dl_handles;
52 extern struct elf_resolve *_dl_loaded_modules;
53 extern struct r_debug *_dl_debug_addr;
54 extern unsigned long _dl_error_number;
55 extern void *(*_dl_malloc_function)(size_t);
56 extern void (*_dl_free_function) (void *p);
57 extern void _dl_run_init_array(struct elf_resolve *);
58 extern void _dl_run_fini_array(struct elf_resolve *);
59 #ifdef __LDSO_CACHE_SUPPORT__
60 int _dl_map_cache(void);
61 int _dl_unmap_cache(void);
64 extern void _dl_perform_mips_global_got_relocations(struct elf_resolve *tpnt, int lazy);
66 #ifdef __SUPPORT_LD_DEBUG__
67 extern char *_dl_debug;
73 #define _dl_malloc malloc
76 /* When libdl is linked as a static library, we need to replace all
77 * the symbols that otherwise would have been loaded in from ldso... */
79 #ifdef __SUPPORT_LD_DEBUG__
81 char *_dl_debug_symbols = 0;
82 char *_dl_debug_move = 0;
83 char *_dl_debug_reloc = 0;
84 char *_dl_debug_detail = 0;
85 char *_dl_debug_nofixups = 0;
86 char *_dl_debug_bindings = 0;
87 int _dl_debug_file = 2;
89 const char *_dl_progname = ""; /* Program name */
90 void *(*_dl_malloc_function)(size_t);
91 void (*_dl_free_function) (void *p);
92 char *_dl_library_path = 0; /* Where we look for libraries */
93 char *_dl_ldsopath = 0; /* Location of the shared lib loader */
94 int _dl_errno = 0; /* We can't use the real errno in ldso */
95 size_t _dl_pagesize = PAGE_SIZE; /* Store the page size for use later */
96 /* This global variable is also to communicate with debuggers such as gdb. */
97 struct r_debug *_dl_debug_addr = NULL;
99 #include "../ldso/dl-array.c"
100 #include "../ldso/dl-debug.c"
101 #include LDSO_ELFINTERP
102 #include "../ldso/dl-hash.c"
103 #define _dl_trace_loaded_objects 0
104 #include "../ldso/dl-elf.c"
107 #ifdef __SUPPORT_LD_DEBUG__
108 # define _dl_if_debug_print(fmt, args...) \
111 fprintf(stderr, "%s():%i: " fmt, __FUNCTION__, __LINE__, ## args); \
114 # define _dl_if_debug_print(fmt, args...)
117 static int do_dlclose(void *, int need_fini);
120 static const char *dl_error_names[] = {
123 "Unable to open /dev/zero",
125 #if defined (__i386__)
127 #elif defined (__sparc__)
129 #elif defined (__mc68000__)
132 "Unrecognized binary type",
134 "Not an ELF shared library",
135 "Unable to mmap file",
136 "No dynamic section",
137 #ifdef ELF_USES_RELOCA
138 "Unable to process REL relocs",
140 "Unable to process RELA relocs",
143 "Unable to resolve symbol"
146 void dl_cleanup(void) __attribute__ ((destructor));
147 void dl_cleanup(void)
150 for (d = _dl_handles; d; d = d->next_handle) {
155 void *dlopen(const char *libname, int flag)
157 struct elf_resolve *tpnt, *tfrom;
158 struct dyn_elf *dyn_chain, *rpnt = NULL, *dyn_ptr, *relro_ptr, *handle;
160 struct elf_resolve *tpnt1;
161 void (*dl_brk) (void);
163 struct init_fini_list *tmp, *runp, *runp2, *dep_list;
164 unsigned int nlist, i;
165 struct elf_resolve **init_fini_list;
166 static bool _dl_init;
168 /* A bit of sanity checking... */
169 if (!(flag & (RTLD_LAZY|RTLD_NOW))) {
170 _dl_error_number = LD_BAD_HANDLE;
174 from = (ElfW(Addr)) __builtin_return_address(0);
178 _dl_malloc_function = malloc;
179 _dl_free_function = free;
181 /* Cover the trivial case first */
183 return _dl_symbol_tables;
186 # ifdef __SUPPORT_LD_DEBUG__
187 _dl_debug = getenv("LD_DEBUG");
189 if (_dl_strstr(_dl_debug, "all")) {
190 _dl_debug_detail = _dl_debug_move = _dl_debug_symbols
191 = _dl_debug_reloc = _dl_debug_bindings = _dl_debug_nofixups = (void*)1;
193 _dl_debug_detail = strstr(_dl_debug, "detail");
194 _dl_debug_move = strstr(_dl_debug, "move");
195 _dl_debug_symbols = strstr(_dl_debug, "sym");
196 _dl_debug_reloc = strstr(_dl_debug, "reloc");
197 _dl_debug_nofixups = strstr(_dl_debug, "nofix");
198 _dl_debug_bindings = strstr(_dl_debug, "bind");
207 * Try and locate the module we were called from - we
208 * need this so that we get the correct RPATH/RUNPATH. Note that
209 * this is the current behavior under Solaris, but the
210 * ABI+ specifies that we should only use the RPATH from
211 * the application. Thus this may go away at some time
215 struct dyn_elf *dpnt;
217 for (dpnt = _dl_symbol_tables; dpnt; dpnt = dpnt->next) {
219 if (DL_ADDR_IN_LOADADDR(from, tpnt, tfrom))
223 for (rpnt = _dl_symbol_tables; rpnt && rpnt->next; rpnt=rpnt->next);
226 now_flag = (flag & RTLD_NOW) ? RTLD_NOW : 0;
227 if (getenv("LD_BIND_NOW"))
231 /* When statically linked, the _dl_library_path is not yet initialized */
232 _dl_library_path = getenv("LD_LIBRARY_PATH");
235 /* Try to load the specified library */
236 _dl_if_debug_print("Trying to dlopen '%s', RTLD_GLOBAL:%d RTLD_NOW:%d\n",
237 (char*)libname, (flag & RTLD_GLOBAL ? 1:0), (now_flag & RTLD_NOW ? 1:0));
238 tpnt = _dl_load_shared_library(0, &rpnt, tfrom, (char*)libname, 0);
244 dyn_chain = (struct dyn_elf *) malloc(sizeof(struct dyn_elf));
245 _dl_memset(dyn_chain, 0, sizeof(struct dyn_elf));
246 dyn_chain->dyn = tpnt;
247 tpnt->rtld_flags |= (flag & RTLD_GLOBAL);
249 dyn_chain->next_handle = _dl_handles;
250 _dl_handles = dyn_ptr = dyn_chain;
252 if (tpnt->usage_count > 1) {
253 _dl_if_debug_print("Lib: %s already opened\n", libname);
254 /* see if there is a handle from a earlier dlopen */
255 for (handle = _dl_handles->next_handle; handle; handle = handle->next_handle) {
256 if (handle->dyn == tpnt) {
257 dyn_chain->init_fini.init_fini = handle->init_fini.init_fini;
258 dyn_chain->init_fini.nlist = handle->init_fini.nlist;
259 for (i = 0; i < dyn_chain->init_fini.nlist; i++)
260 dyn_chain->init_fini.init_fini[i]->rtld_flags |= (flag & RTLD_GLOBAL);
261 dyn_chain->next = handle->next;
267 tpnt->init_flag |= DL_OPENED;
270 _dl_if_debug_print("Looking for needed libraries\n");
272 runp = alloca(sizeof(*runp));
275 dep_list = runp2 = runp;
276 for (; runp; runp = runp->next)
282 runp->tpnt->init_fini = NULL; /* clear any previous dependcies */
283 for (dpnt = (ElfW(Dyn) *) runp->tpnt->dynamic_addr; dpnt->d_tag; dpnt++) {
284 if (dpnt->d_tag == DT_NEEDED) {
285 lpntstr = (char*) (runp->tpnt->dynamic_info[DT_STRTAB] +
287 _dl_if_debug_print("Trying to load '%s', needed by '%s'\n",
288 lpntstr, runp->tpnt->libname);
289 tpnt1 = _dl_load_shared_library(0, &rpnt, runp->tpnt, lpntstr, 0);
293 tpnt1->rtld_flags |= (flag & RTLD_GLOBAL);
295 /* This list is for dlsym() and relocation */
296 dyn_ptr->next = (struct dyn_elf *) malloc(sizeof(struct dyn_elf));
297 _dl_memset (dyn_ptr->next, 0, sizeof (struct dyn_elf));
298 dyn_ptr = dyn_ptr->next;
299 dyn_ptr->dyn = tpnt1;
300 /* Used to record RTLD_LOCAL scope */
301 tmp = alloca(sizeof(struct init_fini_list));
303 tmp->next = runp->tpnt->init_fini;
304 runp->tpnt->init_fini = tmp;
306 for (tmp=dep_list; tmp; tmp = tmp->next) {
307 if (tpnt1 == tmp->tpnt) { /* if match => cirular dependency, drop it */
308 _dl_if_debug_print("Circular dependency, skipping '%s',\n",
310 tpnt1->usage_count--;
314 if (!tmp) { /* Don't add if circular dependency detected */
315 runp2->next = alloca(sizeof(*runp));
323 init_fini_list = malloc(nlist * sizeof(struct elf_resolve *));
324 dyn_chain->init_fini.init_fini = init_fini_list;
325 dyn_chain->init_fini.nlist = nlist;
327 for (runp2 = dep_list; runp2; runp2 = runp2->next) {
328 init_fini_list[i++] = runp2->tpnt;
329 for (runp = runp2->tpnt->init_fini; runp; runp = runp->next) {
330 if (!(runp->tpnt->rtld_flags & RTLD_GLOBAL)) {
331 tmp = malloc(sizeof(struct init_fini_list));
332 tmp->tpnt = runp->tpnt;
333 tmp->next = runp2->tpnt->rtld_local;
334 runp2->tpnt->rtld_local = tmp;
339 /* Sort the INIT/FINI list in dependency order. */
340 for (runp2 = dep_list; runp2; runp2 = runp2->next) {
342 for (j = 0; init_fini_list[j] != runp2->tpnt; ++j)
344 for (k = j + 1; k < nlist; ++k) {
345 struct init_fini_list *ele = init_fini_list[k]->init_fini;
347 for (; ele; ele = ele->next) {
348 if (ele->tpnt == runp2->tpnt) {
349 struct elf_resolve *here = init_fini_list[k];
350 _dl_if_debug_print("Move %s from pos %d to %d in INIT/FINI list.\n", here->libname, k, j);
351 for (i = (k - j); i; --i)
352 init_fini_list[i+j] = init_fini_list[i+j-1];
353 init_fini_list[j] = here;
360 #ifdef __SUPPORT_LD_DEBUG__
362 fprintf(stderr, "\nINIT/FINI order and dependencies:\n");
363 for (i = 0; i < nlist; i++) {
364 fprintf(stderr, "lib: %s has deps:\n", init_fini_list[i]->libname);
365 runp = init_fini_list[i]->init_fini;
366 for (; runp; runp = runp->next)
367 printf(" %s ", runp->tpnt->libname);
373 _dl_if_debug_print("Beginning dlopen relocation fixups\n");
375 * OK, now all of the kids are tucked into bed in their proper addresses.
376 * Now we go through and look for REL and RELA records that indicate fixups
377 * to the GOT tables. We need to do this in reverse order so that COPY
378 * directives work correctly */
381 * Relocation of the GOT entries for MIPS have to be done
382 * after all the libraries have been loaded.
384 _dl_perform_mips_global_got_relocations(tpnt, !now_flag);
387 if (_dl_fixup(dyn_chain, now_flag))
391 for (rpnt = relro_ptr->next; rpnt; rpnt = rpnt->next) {
392 if (rpnt->dyn->relro_size)
393 _dl_protect_relro(rpnt->dyn);
396 /* TODO: Should we set the protections of all pages back to R/O now ? */
399 /* Notify the debugger we have added some objects. */
400 if (_dl_debug_addr) {
401 dl_brk = (void (*)(void)) _dl_debug_addr->r_brk;
402 if (dl_brk != NULL) {
403 _dl_debug_addr->r_state = RT_ADD;
406 _dl_debug_addr->r_state = RT_CONSISTENT;
411 /* Run the ctors and setup the dtors */
412 for (i = nlist; i; --i) {
413 tpnt = init_fini_list[i-1];
414 if (tpnt->init_flag & INIT_FUNCS_CALLED)
416 tpnt->init_flag |= INIT_FUNCS_CALLED;
418 if (tpnt->dynamic_info[DT_INIT]) {
419 void (*dl_elf_func) (void);
420 dl_elf_func = (void (*)(void)) DL_RELOC_ADDR(tpnt->loadaddr, tpnt->dynamic_info[DT_INIT]);
422 _dl_if_debug_print("running ctors for library %s at '%p'\n",
423 tpnt->libname, dl_elf_func);
424 DL_CALL_FUNC_AT_ADDR (dl_elf_func, tpnt->loadaddr, (void(*)(void)));
428 _dl_run_init_array(tpnt);
432 return (void *) dyn_chain;
435 /* Something went wrong. Clean up and return NULL. */
437 do_dlclose(dyn_chain, 0);
441 void *dlsym(void *vhandle, const char *name)
443 struct elf_resolve *tpnt, *tfrom;
444 struct dyn_elf *handle;
446 struct dyn_elf *rpnt;
448 /* Nastiness to support underscore prefixes. */
449 #ifdef __UCLIBC_UNDERSCORES__
451 char *name2 = tmp_buf;
452 size_t nlen = strlen (name) + 1;
453 if (nlen + 1 > sizeof (tmp_buf))
454 name2 = malloc (nlen + 1);
456 _dl_error_number = LD_ERROR_MMAP_FAILED;
460 memcpy (name2 + 1, name, nlen);
462 const char *name2 = name;
464 handle = (struct dyn_elf *) vhandle;
466 /* First of all verify that we have a real handle
467 of some kind. Return NULL if not a valid handle. */
470 handle = _dl_symbol_tables;
471 else if (handle != RTLD_NEXT && handle != _dl_symbol_tables) {
472 for (rpnt = _dl_handles; rpnt; rpnt = rpnt->next_handle)
476 _dl_error_number = LD_BAD_HANDLE;
480 } else if (handle == RTLD_NEXT) {
482 * Try and locate the module we were called from - we
483 * need this so that we know where to start searching
484 * from. We never pass RTLD_NEXT down into the actual
485 * dynamic loader itself, as it doesn't know
486 * how to properly treat it.
488 from = (ElfW(Addr)) __builtin_return_address(0);
491 for (rpnt = _dl_symbol_tables; rpnt; rpnt = rpnt->next) {
493 if (DL_ADDR_IN_LOADADDR(from, tpnt, tfrom)) {
500 if (handle == _dl_symbol_tables)
501 tpnt = handle->dyn; /* Only search RTLD_GLOBAL objs if global object */
502 ret = _dl_find_hash(name2, handle, tpnt, ELF_RTYPE_CLASS_DLSYM);
508 _dl_error_number = LD_NO_SYMBOL;
510 #ifdef __UCLIBC_UNDERSCORES__
511 if (name2 != tmp_buf)
518 void *dlvsym(void *vhandle, const char *name, const char *version)
520 return dlsym(vhandle, name);
524 static int do_dlclose(void *vhandle, int need_fini)
526 struct dyn_elf *rpnt, *rpnt1, *rpnt1_tmp;
527 struct init_fini_list *runp, *tmp;
529 struct elf_resolve *tpnt, *run_tpnt;
530 int (*dl_elf_fini) (void);
531 void (*dl_brk) (void);
532 struct dyn_elf *handle;
536 handle = (struct dyn_elf *) vhandle;
537 if (handle == _dl_symbol_tables)
540 for (rpnt = _dl_handles; rpnt; rpnt = rpnt->next_handle) {
547 _dl_error_number = LD_BAD_HANDLE;
551 rpnt1->next_handle = rpnt->next_handle;
553 _dl_handles = rpnt->next_handle;
554 _dl_if_debug_print("%s: usage count: %d\n",
555 handle->dyn->libname, handle->dyn->usage_count);
556 if (handle->dyn->usage_count != 1) {
557 handle->dyn->usage_count--;
561 /* OK, this is a valid handle - now close out the file */
562 for (j = 0; j < handle->init_fini.nlist; ++j) {
563 tpnt = handle->init_fini.init_fini[j];
564 if (--tpnt->usage_count == 0) {
565 if ((tpnt->dynamic_info[DT_FINI]
566 || tpnt->dynamic_info[DT_FINI_ARRAY])
568 !(tpnt->init_flag & FINI_FUNCS_CALLED)) {
569 tpnt->init_flag |= FINI_FUNCS_CALLED;
570 _dl_run_fini_array(tpnt);
572 if (tpnt->dynamic_info[DT_FINI]) {
573 dl_elf_fini = (int (*)(void)) DL_RELOC_ADDR(tpnt->loadaddr, tpnt->dynamic_info[DT_FINI]);
574 _dl_if_debug_print("running dtors for library %s at '%p'\n",
575 tpnt->libname, dl_elf_fini);
576 DL_CALL_FUNC_AT_ADDR (dl_elf_fini, tpnt->loadaddr, (int (*)(void)));
580 _dl_if_debug_print("unmapping: %s\n", tpnt->libname);
582 for (i = 0, ppnt = tpnt->ppnt;
583 i < tpnt->n_phent; ppnt++, i++) {
584 if (ppnt->p_type != PT_LOAD)
586 if (end < ppnt->p_vaddr + ppnt->p_memsz)
587 end = ppnt->p_vaddr + ppnt->p_memsz;
589 DL_LIB_UNMAP (tpnt, end);
590 /* Free elements in RTLD_LOCAL scope list */
591 for (runp = tpnt->rtld_local; runp; runp = tmp) {
596 /* Next, remove tpnt from the loaded_module list */
597 if (_dl_loaded_modules == tpnt) {
598 _dl_loaded_modules = tpnt->next;
599 if (_dl_loaded_modules)
600 _dl_loaded_modules->prev = 0;
602 for (run_tpnt = _dl_loaded_modules; run_tpnt; run_tpnt = run_tpnt->next)
603 if (run_tpnt->next == tpnt) {
604 _dl_if_debug_print("removing loaded_modules: %s\n", tpnt->libname);
605 run_tpnt->next = run_tpnt->next->next;
607 run_tpnt->next->prev = run_tpnt;
611 /* Next, remove tpnt from the global symbol table list */
612 if (_dl_symbol_tables) {
613 if (_dl_symbol_tables->dyn == tpnt) {
614 _dl_symbol_tables = _dl_symbol_tables->next;
615 if (_dl_symbol_tables)
616 _dl_symbol_tables->prev = 0;
618 for (rpnt1 = _dl_symbol_tables; rpnt1->next; rpnt1 = rpnt1->next) {
619 if (rpnt1->next->dyn == tpnt) {
620 _dl_if_debug_print("removing symbol_tables: %s\n", tpnt->libname);
621 rpnt1_tmp = rpnt1->next->next;
623 rpnt1->next = rpnt1_tmp;
625 rpnt1->next->prev = rpnt1;
634 free(handle->init_fini.init_fini);
638 if (_dl_debug_addr) {
639 dl_brk = (void (*)(void)) _dl_debug_addr->r_brk;
640 if (dl_brk != NULL) {
641 _dl_debug_addr->r_state = RT_DELETE;
644 _dl_debug_addr->r_state = RT_CONSISTENT;
652 int dlclose(void *vhandle)
654 return do_dlclose(vhandle, 1);
661 if (!_dl_error_number)
663 retval = dl_error_names[_dl_error_number];
664 _dl_error_number = 0;
665 return (char *)retval;
669 * Dump information to stderr about the current loaded modules
672 static char *type[] = { "Lib", "Exe", "Int", "Mod" };
676 struct elf_resolve *tpnt;
677 struct dyn_elf *rpnt, *hpnt;
679 fprintf(stderr, "List of loaded modules\n");
680 /* First start with a complete list of all of the loaded files. */
681 for (tpnt = _dl_loaded_modules; tpnt; tpnt = tpnt->next) {
682 fprintf(stderr, "\t%p %p %p %s %d %s\n",
683 DL_LOADADDR_BASE(tpnt->loadaddr), tpnt, tpnt->symbol_scope,
685 tpnt->usage_count, tpnt->libname);
688 /* Next dump the module list for the application itself */
689 fprintf(stderr, "\nModules for application (%p):\n", _dl_symbol_tables);
690 for (rpnt = _dl_symbol_tables; rpnt; rpnt = rpnt->next)
691 fprintf(stderr, "\t%p %s\n", rpnt->dyn, rpnt->dyn->libname);
693 for (hpnt = _dl_handles; hpnt; hpnt = hpnt->next_handle) {
694 fprintf(stderr, "Modules for handle %p\n", hpnt);
695 for (rpnt = hpnt; rpnt; rpnt = rpnt->next)
696 fprintf(stderr, "\t%p %s\n", rpnt->dyn, rpnt->dyn->libname);
701 int dladdr(const void *__address, Dl_info * __info)
703 struct elf_resolve *pelf;
704 struct elf_resolve *rpnt;
709 * Try and locate the module address is in
713 _dl_if_debug_print("__address: %p __info: %p\n", __address, __info);
715 __address = DL_LOOKUP_ADDRESS (__address);
717 for (rpnt = _dl_loaded_modules; rpnt; rpnt = rpnt->next) {
718 struct elf_resolve *tpnt;
722 _dl_if_debug_print("Module \"%s\" at %p\n",
723 tpnt->libname, DL_LOADADDR_BASE(tpnt->loadaddr));
725 if (DL_ADDR_IN_LOADADDR((ElfW(Addr)) __address, tpnt, pelf))
734 * Try and locate the symbol of address
740 unsigned int hn, si, sn, sf;
743 /* Set the info for the object the address lies in */
744 __info->dli_fname = pelf->libname;
745 __info->dli_fbase = (void *)pelf->mapaddr;
747 symtab = (ElfW(Sym) *) (pelf->dynamic_info[DT_SYMTAB]);
748 strtab = (char *) (pelf->dynamic_info[DT_STRTAB]);
752 #ifdef __LDSO_GNU_HASH_SUPPORT__
753 if (pelf->l_gnu_bitmask) {
754 for (hn = 0; hn < pelf->nbucket; hn++) {
755 si = pelf->l_gnu_buckets[hn];
759 const Elf32_Word *hasharr = &pelf->l_gnu_chain_zero[si];
761 ElfW(Addr) symbol_addr;
763 symbol_addr = (ElfW(Addr)) DL_RELOC_ADDR(pelf->loadaddr, symtab[si].st_value);
764 if (symbol_addr <= (ElfW(Addr))__address && (!sf || sa < symbol_addr)) {
769 _dl_if_debug_print("Symbol \"%s\" at %p\n", strtab + symtab[si].st_name, symbol_addr);
771 } while ((*hasharr++ & 1u) == 0);
775 for (hn = 0; hn < pelf->nbucket; hn++) {
776 for (si = pelf->elf_buckets[hn]; si; si = pelf->chains[si]) {
777 ElfW(Addr) symbol_addr;
779 symbol_addr = (ElfW(Addr)) DL_RELOC_ADDR(pelf->loadaddr, symtab[si].st_value);
780 if (symbol_addr <= (ElfW(Addr))__address && (!sf || sa < symbol_addr)) {
786 _dl_if_debug_print("Symbol \"%s\" at %p\n",
787 strtab + symtab[si].st_name, symbol_addr);
792 /* A nearest symbol has been found; fill the entries */
793 __info->dli_sname = strtab + symtab[sn].st_name;
794 __info->dli_saddr = (void *)sa;
796 /* No symbol found, fill entries with NULL value,
797 only the containing object will be returned. */
798 __info->dli_sname = NULL;
799 __info->dli_saddr = NULL;