1 /* Look up a symbol in the loaded objects.
2 MIPS/Linux version - special handling of non-PIC undefined symbol rules.
3 Copyright (C) 1995-2005, 2006, 2007, 2009 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
28 #include <dl-machine.h>
29 #include <sysdep-cancel.h>
30 #include <bits/libc-lock.h>
35 #define VERSTAG(tag) (DT_NUM + DT_THISPROCNUM + DT_VERSIONTAGIDX (tag))
37 /* We need this string more than once. */
38 static const char undefined_msg
[] = "undefined symbol: ";
48 #define make_string(string, rest...) \
50 const char *all[] = { string, ## rest }; \
55 for (cnt = 0; cnt < sizeof (all) / sizeof (all[0]); ++cnt) \
56 len += strlen (all[cnt]); \
58 cp = result = alloca (len); \
59 for (cnt = 0; cnt < sizeof (all) / sizeof (all[0]); ++cnt) \
60 cp = __stpcpy (cp, all[cnt]); \
65 /* Statistics function. */
67 # define bump_num_relocations() ++GL(dl_num_relocations)
69 # define bump_num_relocations() ((void) 0)
73 /* Inner part of the lookup functions. We return a value > 0 if we
74 found the symbol, the value 0 if nothing is found and < 0 if
75 something bad happened. */
77 __attribute_noinline__
78 do_lookup_x (const char *undef_name
, uint_fast32_t new_hash
,
79 unsigned long int *old_hash
, const ElfW(Sym
) *ref
,
80 struct sym_val
*result
, struct r_scope_elem
*scope
, size_t i
,
81 const struct r_found_version
*const version
, int flags
,
82 struct link_map
*skip
, int type_class
, struct link_map
*undef_map
)
84 size_t n
= scope
->r_nlist
;
85 /* Make sure we read the value before proceeding. Otherwise we
86 might use r_list pointing to the initial scope and r_nlist being
87 the value after a resize. That is the only path in dl-open.c not
88 protected by GSCOPE. A read barrier here might be to expensive. */
89 __asm
volatile ("" : "+r" (n
), "+m" (scope
->r_list
));
90 struct link_map
**list
= scope
->r_list
;
94 /* These variables are used in the nested function. */
97 const ElfW(Sym
) *versioned_sym
= NULL
;
99 const struct link_map
*map
= list
[i
]->l_real
;
101 /* Here come the extra test needed for `_dl_lookup_symbol_skip'. */
105 /* Don't search the executable when resolving a copy reloc. */
106 if ((type_class
& ELF_RTYPE_CLASS_COPY
) && map
->l_type
== lt_executable
)
109 /* Do not look into objects which are going to be removed. */
113 /* Print some debugging info if wanted. */
114 if (__builtin_expect (GLRO(dl_debug_mask
) & DL_DEBUG_SYMBOLS
, 0))
115 _dl_debug_printf ("symbol=%s; lookup in file=%s [%lu]\n",
117 map
->l_name
[0] ? map
->l_name
: rtld_progname
,
120 /* If the hash table is empty there is nothing to do here. */
121 if (map
->l_nbuckets
== 0)
124 /* The tables for this map. */
125 const ElfW(Sym
) *symtab
= (const void *) D_PTR (map
, l_info
[DT_SYMTAB
]);
126 const char *strtab
= (const void *) D_PTR (map
, l_info
[DT_STRTAB
]);
129 /* Nested routine to check whether the symbol matches. */
131 __attribute_noinline__
132 check_match (const ElfW(Sym
) *sym
)
134 unsigned int stt
= ELFW(ST_TYPE
) (sym
->st_info
);
135 assert (ELF_RTYPE_CLASS_PLT
== 1);
136 /* The semantics of zero/non-zero values of undefined symbols
137 differs depending on whether the non-PIC ABI is in use.
138 Under the non-PIC ABI, a non-zero value indicates that
139 there is an address reference to the symbol and thus it
140 must always be resolved (except when resolving a jump slot
141 relocation) to the PLT entry whose address is provided as
142 the symbol's value; a zero value indicates that this
143 canonical-address behaviour is not required. Yet under the
144 classic MIPS psABI, a zero value indicates that there is an
145 address reference to the function and the dynamic linker
146 must resolve the symbol immediately upon loading. To avoid
147 conflict, symbols for which the dynamic linker must assume
148 the non-PIC ABI semantics are marked with the STO_MIPS_PLT
150 if (__builtin_expect ((sym
->st_value
== 0 /* No value. */
152 || (sym
->st_shndx
== SHN_UNDEF
153 && !(sym
->st_other
& STO_MIPS_PLT
))
154 || (type_class
& (sym
->st_shndx
== SHN_UNDEF
)),
158 /* Ignore all but STT_NOTYPE, STT_OBJECT, STT_FUNC,
159 STT_COMMON, STT_TLS, and STT_GNU_IFUNC since these are no
160 code/data definitions. */
161 #define ALLOWED_STT \
162 ((1 << STT_NOTYPE) | (1 << STT_OBJECT) | (1 << STT_FUNC) \
163 | (1 << STT_COMMON) | (1 << STT_TLS) | (1 << STT_GNU_IFUNC))
164 if (__builtin_expect (((1 << stt
) & ALLOWED_STT
) == 0, 0))
167 if (sym
!= ref
&& strcmp (strtab
+ sym
->st_name
, undef_name
))
168 /* Not the symbol we are looking for. */
171 const ElfW(Half
) *verstab
= map
->l_versyms
;
174 if (__builtin_expect (verstab
== NULL
, 0))
176 /* We need a versioned symbol but haven't found any. If
177 this is the object which is referenced in the verneed
178 entry it is a bug in the library since a symbol must
179 not simply disappear.
181 It would also be a bug in the object since it means that
182 the list of required versions is incomplete and so the
183 tests in dl-version.c haven't found a problem.*/
184 assert (version
->filename
== NULL
185 || ! _dl_name_match_p (version
->filename
, map
));
187 /* Otherwise we accept the symbol. */
191 /* We can match the version information or use the
192 default one if it is not hidden. */
193 ElfW(Half
) ndx
= verstab
[symidx
] & 0x7fff;
194 if ((map
->l_versions
[ndx
].hash
!= version
->hash
195 || strcmp (map
->l_versions
[ndx
].name
, version
->name
))
196 && (version
->hidden
|| map
->l_versions
[ndx
].hash
197 || (verstab
[symidx
] & 0x8000)))
198 /* It's not the version we want. */
204 /* No specific version is selected. There are two ways we
207 - a binary which does not include versioning information
210 - dlsym() instead of dlvsym() is used to get a symbol which
211 might exist in more than one form
213 If the library does not provide symbol version information
214 there is no problem at at: we simply use the symbol if it
217 These two lookups need to be handled differently if the
218 library defines versions. In the case of the old
219 unversioned application the oldest (default) version
220 should be used. In case of a dlsym() call the latest and
221 public interface should be returned. */
224 if ((verstab
[symidx
] & 0x7fff)
225 >= ((flags
& DL_LOOKUP_RETURN_NEWEST
) ? 2 : 3))
227 /* Don't accept hidden symbols. */
228 if ((verstab
[symidx
] & 0x8000) == 0
229 && num_versions
++ == 0)
230 /* No version so far. */
238 /* There cannot be another entry for this symbol so stop here. */
242 const ElfW(Sym
) *sym
;
243 const ElfW(Addr
) *bitmask
= map
->l_gnu_bitmask
;
244 if (__builtin_expect (bitmask
!= NULL
, 1))
246 ElfW(Addr
) bitmask_word
247 = bitmask
[(new_hash
/ __ELF_NATIVE_CLASS
)
248 & map
->l_gnu_bitmask_idxbits
];
250 unsigned int hashbit1
= new_hash
& (__ELF_NATIVE_CLASS
- 1);
251 unsigned int hashbit2
= ((new_hash
>> map
->l_gnu_shift
)
252 & (__ELF_NATIVE_CLASS
- 1));
254 if (__builtin_expect ((bitmask_word
>> hashbit1
)
255 & (bitmask_word
>> hashbit2
) & 1, 0))
257 Elf32_Word bucket
= map
->l_gnu_buckets
[new_hash
261 const Elf32_Word
*hasharr
= &map
->l_gnu_chain_zero
[bucket
];
264 if (((*hasharr
^ new_hash
) >> 1) == 0)
266 symidx
= hasharr
- map
->l_gnu_chain_zero
;
267 sym
= check_match (&symtab
[symidx
]);
271 while ((*hasharr
++ & 1u) == 0);
274 /* No symbol found. */
279 if (*old_hash
== 0xffffffff)
280 *old_hash
= _dl_elf_hash (undef_name
);
282 /* Use the old SysV-style hash table. Search the appropriate
283 hash bucket in this object's symbol table for a definition
284 for the same symbol name. */
285 for (symidx
= map
->l_buckets
[*old_hash
% map
->l_nbuckets
];
287 symidx
= map
->l_chain
[symidx
])
289 sym
= check_match (&symtab
[symidx
]);
295 /* If we have seen exactly one versioned symbol while we are
296 looking for an unversioned symbol and the version is not the
297 default version we still accept this symbol since there are
298 no possible ambiguities. */
299 sym
= num_versions
== 1 ? versioned_sym
: NULL
;
304 switch (__builtin_expect (ELFW(ST_BIND
) (sym
->st_info
), STB_GLOBAL
))
307 /* Weak definition. Use this value if we don't find another. */
308 if (__builtin_expect (GLRO(dl_dynamic_weak
), 0))
313 result
->m
= (struct link_map
*) map
;
320 /* Global definition. Just what we need. */
322 result
->m
= (struct link_map
*) map
;
325 case STB_GNU_UNIQUE
:;
326 /* We have to determine whether we already found a
327 symbol with this name before. If not then we have to
328 add it to the search table. If we already found a
329 definition we have to use it. */
330 void enter (struct unique_sym
*table
, size_t size
,
331 unsigned int hash
, const char *name
,
332 const ElfW(Sym
) *sym
, const struct link_map
*map
)
334 size_t idx
= hash
% size
;
335 size_t hash2
= 1 + hash
% (size
- 2);
338 if (table
[idx
].hashval
== 0)
340 table
[idx
].hashval
= hash
;
341 table
[idx
].name
= strtab
+ sym
->st_name
;
342 if ((type_class
& ELF_RTYPE_CLASS_COPY
) != 0)
344 table
[idx
].sym
= ref
;
345 table
[idx
].map
= undef_map
;
349 table
[idx
].sym
= sym
;
350 table
[idx
].map
= map
;
361 struct unique_sym_table
*tab
362 = &GL(dl_ns
)[map
->l_ns
]._ns_unique_sym_table
;
364 __rtld_lock_lock_recursive (tab
->lock
);
366 struct unique_sym
*entries
= tab
->entries
;
367 size_t size
= tab
->size
;
370 size_t idx
= new_hash
% size
;
371 size_t hash2
= 1 + new_hash
% (size
- 2);
374 if (entries
[idx
].hashval
== new_hash
375 && strcmp (entries
[idx
].name
, undef_name
) == 0)
377 result
->s
= entries
[idx
].sym
;
378 result
->m
= (struct link_map
*) entries
[idx
].map
;
379 __rtld_lock_unlock_recursive (tab
->lock
);
383 if (entries
[idx
].hashval
== 0
384 && entries
[idx
].name
== NULL
)
392 if (size
* 3 <= tab
->n_elements
)
394 /* Expand the table. */
395 size_t newsize
= _dl_higher_prime_number (size
);
396 struct unique_sym
*newentries
397 = calloc (sizeof (struct unique_sym
), newsize
);
398 if (newentries
== NULL
)
401 __rtld_lock_unlock_recursive (tab
->lock
);
402 _dl_fatal_printf ("out of memory\n");
405 for (idx
= 0; idx
< size
; ++idx
)
406 if (entries
[idx
].hashval
!= 0)
407 enter (newentries
, newsize
, entries
[idx
].hashval
,
408 entries
[idx
].name
, entries
[idx
].sym
,
413 entries
= tab
->entries
= newentries
;
419 #define INITIAL_NUNIQUE_SYM_TABLE 31
420 size
= INITIAL_NUNIQUE_SYM_TABLE
;
421 entries
= calloc (sizeof (struct unique_sym
), size
);
425 tab
->entries
= entries
;
430 enter (entries
, size
, new_hash
, strtab
+ sym
->st_name
, sym
, map
);
433 __rtld_lock_unlock_recursive (tab
->lock
);
438 /* Local symbols are ignored. */
443 /* If this current map is the one mentioned in the verneed entry
444 and we have not found a weak entry, it is a bug. */
445 if (symidx
== STN_UNDEF
&& version
!= NULL
&& version
->filename
!= NULL
446 && __builtin_expect (_dl_name_match_p (version
->filename
, map
), 0))
451 /* We have not found anything until now. */
457 dl_new_hash (const char *s
)
459 uint_fast32_t h
= 5381;
460 for (unsigned char c
= *s
; c
!= '\0'; c
= *++s
)
462 return h
& 0xffffffff;
466 /* Add extra dependency on MAP to UNDEF_MAP. */
469 add_dependency (struct link_map
*undef_map
, struct link_map
*map
, int flags
)
471 struct link_map
*runp
;
475 /* Avoid self-references and references to objects which cannot be
477 if (undef_map
== map
)
480 /* Avoid references to objects which cannot be unloaded anyway. */
481 assert (map
->l_type
== lt_loaded
);
482 if ((map
->l_flags_1
& DF_1_NODELETE
) != 0)
485 struct link_map_reldeps
*l_reldeps
486 = atomic_forced_read (undef_map
->l_reldeps
);
488 /* Make sure l_reldeps is read before l_initfini. */
489 atomic_read_barrier ();
491 /* Determine whether UNDEF_MAP already has a reference to MAP. First
492 look in the normal dependencies. */
493 struct link_map
**l_initfini
= atomic_forced_read (undef_map
->l_initfini
);
494 if (l_initfini
!= NULL
)
496 for (i
= 0; l_initfini
[i
] != NULL
; ++i
)
497 if (l_initfini
[i
] == map
)
501 /* No normal dependency. See whether we already had to add it
502 to the special list of dynamic dependencies. */
503 unsigned int l_reldepsact
= 0;
504 if (l_reldeps
!= NULL
)
506 struct link_map
**list
= &l_reldeps
->list
[0];
507 l_reldepsact
= l_reldeps
->act
;
508 for (i
= 0; i
< l_reldepsact
; ++i
)
513 /* Save serial number of the target MAP. */
514 unsigned long long serial
= map
->l_serial
;
516 /* Make sure nobody can unload the object while we are at it. */
517 if (__builtin_expect (flags
& DL_LOOKUP_GSCOPE_LOCK
, 0))
519 /* We can't just call __rtld_lock_lock_recursive (GL(dl_load_lock))
520 here, that can result in ABBA deadlock. */
521 THREAD_GSCOPE_RESET_FLAG ();
522 __rtld_lock_lock_recursive (GL(dl_load_lock
));
523 /* While MAP value won't change, after THREAD_GSCOPE_RESET_FLAG ()
524 it can e.g. point to unallocated memory. So avoid the optimizer
525 treating the above read from MAP->l_serial as ensurance it
526 can safely dereference it. */
527 map
= atomic_forced_read (map
);
529 /* From this point on it is unsafe to dereference MAP, until it
530 has been found in one of the lists. */
532 /* Redo the l_initfini check in case undef_map's l_initfini
533 changed in the mean time. */
534 if (undef_map
->l_initfini
!= l_initfini
535 && undef_map
->l_initfini
!= NULL
)
537 l_initfini
= undef_map
->l_initfini
;
538 for (i
= 0; l_initfini
[i
] != NULL
; ++i
)
539 if (l_initfini
[i
] == map
)
543 /* Redo the l_reldeps check if undef_map's l_reldeps changed in
545 if (undef_map
->l_reldeps
!= NULL
)
547 if (undef_map
->l_reldeps
!= l_reldeps
)
549 struct link_map
**list
= &undef_map
->l_reldeps
->list
[0];
550 l_reldepsact
= undef_map
->l_reldeps
->act
;
551 for (i
= 0; i
< l_reldepsact
; ++i
)
555 else if (undef_map
->l_reldeps
->act
> l_reldepsact
)
557 struct link_map
**list
558 = &undef_map
->l_reldeps
->list
[0];
560 l_reldepsact
= undef_map
->l_reldeps
->act
;
561 for (; i
< l_reldepsact
; ++i
)
568 __rtld_lock_lock_recursive (GL(dl_load_lock
));
570 /* The object is not yet in the dependency list. Before we add
571 it make sure just one more time the object we are about to
572 reference is still available. There is a brief period in
573 which the object could have been removed since we found the
575 runp
= GL(dl_ns
)[undef_map
->l_ns
]._ns_loaded
;
576 while (runp
!= NULL
&& runp
!= map
)
581 /* The object is still available. */
583 /* MAP could have been dlclosed, freed and then some other dlopened
584 library could have the same link_map pointer. */
585 if (map
->l_serial
!= serial
)
588 /* Redo the NODELETE check, as when dl_load_lock wasn't held
589 yet this could have changed. */
590 if ((map
->l_flags_1
& DF_1_NODELETE
) != 0)
593 /* If the object with the undefined reference cannot be removed ever
594 just make sure the same is true for the object which contains the
596 if (undef_map
->l_type
!= lt_loaded
597 || (undef_map
->l_flags_1
& DF_1_NODELETE
) != 0)
599 map
->l_flags_1
|= DF_1_NODELETE
;
603 /* Add the reference now. */
604 if (__builtin_expect (l_reldepsact
>= undef_map
->l_reldepsmax
, 0))
606 /* Allocate more memory for the dependency list. Since this
607 can never happen during the startup phase we can use
609 struct link_map_reldeps
*newp
;
611 = undef_map
->l_reldepsmax
? undef_map
->l_reldepsmax
* 2 : 10;
613 newp
= malloc (sizeof (*newp
) + max
* sizeof (struct link_map
*));
616 /* If we didn't manage to allocate memory for the list this is
617 no fatal problem. We simply make sure the referenced object
618 cannot be unloaded. This is semantically the correct
620 map
->l_flags_1
|= DF_1_NODELETE
;
626 memcpy (&newp
->list
[0], &undef_map
->l_reldeps
->list
[0],
627 l_reldepsact
* sizeof (struct link_map
*));
628 newp
->list
[l_reldepsact
] = map
;
629 newp
->act
= l_reldepsact
+ 1;
630 atomic_write_barrier ();
631 void *old
= undef_map
->l_reldeps
;
632 undef_map
->l_reldeps
= newp
;
633 undef_map
->l_reldepsmax
= max
;
635 _dl_scope_free (old
);
640 undef_map
->l_reldeps
->list
[l_reldepsact
] = map
;
641 atomic_write_barrier ();
642 undef_map
->l_reldeps
->act
= l_reldepsact
+ 1;
645 /* Display information if we are debugging. */
646 if (__builtin_expect (GLRO(dl_debug_mask
) & DL_DEBUG_FILES
, 0))
648 \nfile=%s [%lu]; needed by %s [%lu] (relocation dependency)\n\n",
649 map
->l_name
[0] ? map
->l_name
: rtld_progname
,
652 ? undef_map
->l_name
: rtld_progname
,
656 /* Whoa, that was bad luck. We have to search again. */
660 /* Release the lock. */
661 __rtld_lock_unlock_recursive (GL(dl_load_lock
));
663 if (__builtin_expect (flags
& DL_LOOKUP_GSCOPE_LOCK
, 0))
664 THREAD_GSCOPE_SET_FLAG ();
669 if (map
->l_serial
!= serial
)
676 _dl_debug_bindings (const char *undef_name
, struct link_map
*undef_map
,
677 const ElfW(Sym
) **ref
, struct sym_val
*value
,
678 const struct r_found_version
*version
, int type_class
,
682 /* Search loaded objects' symbol tables for a definition of the symbol
683 UNDEF_NAME, perhaps with a requested version for the symbol.
685 We must never have calls to the audit functions inside this function
686 or in any function which gets called. If this would happen the audit
687 code might create a thread which can throw off all the scope locking. */
690 _dl_lookup_symbol_x (const char *undef_name
, struct link_map
*undef_map
,
691 const ElfW(Sym
) **ref
,
692 struct r_scope_elem
*symbol_scope
[],
693 const struct r_found_version
*version
,
694 int type_class
, int flags
, struct link_map
*skip_map
)
696 const uint_fast32_t new_hash
= dl_new_hash (undef_name
);
697 unsigned long int old_hash
= 0xffffffff;
698 struct sym_val current_value
= { NULL
, NULL
};
699 struct r_scope_elem
**scope
= symbol_scope
;
701 bump_num_relocations ();
703 /* No other flag than DL_LOOKUP_ADD_DEPENDENCY or DL_LOOKUP_GSCOPE_LOCK
704 is allowed if we look up a versioned symbol. */
705 assert (version
== NULL
706 || (flags
& ~(DL_LOOKUP_ADD_DEPENDENCY
| DL_LOOKUP_GSCOPE_LOCK
))
710 if (__builtin_expect (skip_map
!= NULL
, 0))
711 /* Search the relevant loaded objects for a definition. */
712 while ((*scope
)->r_list
[i
] != skip_map
)
715 /* Search the relevant loaded objects for a definition. */
716 for (size_t start
= i
; *scope
!= NULL
; start
= 0, ++scope
)
718 int res
= do_lookup_x (undef_name
, new_hash
, &old_hash
, *ref
,
719 ¤t_value
, *scope
, start
, version
, flags
,
720 skip_map
, type_class
, undef_map
);
724 if (__builtin_expect (res
, 0) < 0 && skip_map
== NULL
)
726 /* Oh, oh. The file named in the relocation entry does not
727 contain the needed symbol. This code is never reached
728 for unversioned lookups. */
729 assert (version
!= NULL
);
730 const char *reference_name
= undef_map
? undef_map
->l_name
: NULL
;
732 /* XXX We cannot translate the message. */
733 _dl_signal_cerror (0, (reference_name
[0]
735 : (rtld_progname
?: "<main program>")),
736 N_("relocation error"),
737 make_string ("symbol ", undef_name
, ", version ",
739 " not defined in file ",
741 " with link time reference",
743 ? " (no version symbols)" : ""));
749 if (__builtin_expect (current_value
.s
== NULL
, 0))
751 if ((*ref
== NULL
|| ELFW(ST_BIND
) ((*ref
)->st_info
) != STB_WEAK
)
754 /* We could find no value for a strong reference. */
755 const char *reference_name
= undef_map
? undef_map
->l_name
: "";
756 const char *versionstr
= version
? ", version " : "";
757 const char *versionname
= (version
&& version
->name
758 ? version
->name
: "");
760 /* XXX We cannot translate the message. */
761 _dl_signal_cerror (0, (reference_name
[0]
763 : (rtld_progname
?: "<main program>")),
764 N_("symbol lookup error"),
765 make_string (undefined_msg
, undef_name
,
766 versionstr
, versionname
));
772 int protected = (*ref
773 && ELFW(ST_VISIBILITY
) ((*ref
)->st_other
) == STV_PROTECTED
);
774 if (__builtin_expect (protected != 0, 0))
776 /* It is very tricky. We need to figure out what value to
777 return for the protected symbol. */
778 if (type_class
== ELF_RTYPE_CLASS_PLT
)
780 if (current_value
.s
!= NULL
&& current_value
.m
!= undef_map
)
782 current_value
.s
= *ref
;
783 current_value
.m
= undef_map
;
788 struct sym_val protected_value
= { NULL
, NULL
};
790 for (scope
= symbol_scope
; *scope
!= NULL
; i
= 0, ++scope
)
791 if (do_lookup_x (undef_name
, new_hash
, &old_hash
, *ref
,
792 &protected_value
, *scope
, i
, version
, flags
,
793 skip_map
, ELF_RTYPE_CLASS_PLT
, NULL
) != 0)
796 if (protected_value
.s
!= NULL
&& protected_value
.m
!= undef_map
)
798 current_value
.s
= *ref
;
799 current_value
.m
= undef_map
;
804 /* We have to check whether this would bind UNDEF_MAP to an object
805 in the global scope which was dynamically loaded. In this case
806 we have to prevent the latter from being unloaded unless the
807 UNDEF_MAP object is also unloaded. */
808 if (__builtin_expect (current_value
.m
->l_type
== lt_loaded
, 0)
809 /* Don't do this for explicit lookups as opposed to implicit
811 && (flags
& DL_LOOKUP_ADD_DEPENDENCY
) != 0
812 /* Add UNDEF_MAP to the dependencies. */
813 && add_dependency (undef_map
, current_value
.m
, flags
) < 0)
814 /* Something went wrong. Perhaps the object we tried to reference
815 was just removed. Try finding another definition. */
816 return _dl_lookup_symbol_x (undef_name
, undef_map
, ref
,
817 (flags
& DL_LOOKUP_GSCOPE_LOCK
)
818 ? undef_map
->l_scope
: symbol_scope
,
819 version
, type_class
, flags
, skip_map
);
821 /* The object is used. */
822 current_value
.m
->l_used
= 1;
824 if (__builtin_expect (GLRO(dl_debug_mask
)
825 & (DL_DEBUG_BINDINGS
|DL_DEBUG_PRELINK
), 0))
826 _dl_debug_bindings (undef_name
, undef_map
, ref
,
827 ¤t_value
, version
, type_class
, protected);
829 *ref
= current_value
.s
;
830 return LOOKUP_VALUE (current_value
.m
);
834 /* Cache the location of MAP's hash table. */
838 _dl_setup_hash (struct link_map
*map
)
843 if (__builtin_expect (map
->l_info
[DT_ADDRTAGIDX (DT_GNU_HASH
) + DT_NUM
844 + DT_THISPROCNUM
+ DT_VERSIONTAGNUM
845 + DT_EXTRANUM
+ DT_VALNUM
] != NULL
, 1))
848 = (void *) D_PTR (map
, l_info
[DT_ADDRTAGIDX (DT_GNU_HASH
) + DT_NUM
849 + DT_THISPROCNUM
+ DT_VERSIONTAGNUM
850 + DT_EXTRANUM
+ DT_VALNUM
]);
851 map
->l_nbuckets
= *hash32
++;
852 Elf32_Word symbias
= *hash32
++;
853 Elf32_Word bitmask_nwords
= *hash32
++;
854 /* Must be a power of two. */
855 assert ((bitmask_nwords
& (bitmask_nwords
- 1)) == 0);
856 map
->l_gnu_bitmask_idxbits
= bitmask_nwords
- 1;
857 map
->l_gnu_shift
= *hash32
++;
859 map
->l_gnu_bitmask
= (ElfW(Addr
) *) hash32
;
860 hash32
+= __ELF_NATIVE_CLASS
/ 32 * bitmask_nwords
;
862 map
->l_gnu_buckets
= hash32
;
863 hash32
+= map
->l_nbuckets
;
864 map
->l_gnu_chain_zero
= hash32
- symbias
;
868 if (!map
->l_info
[DT_HASH
])
870 hash
= (void *) D_PTR (map
, l_info
[DT_HASH
]);
872 map
->l_nbuckets
= *hash
++;
874 map
->l_buckets
= hash
;
875 hash
+= map
->l_nbuckets
;
882 _dl_debug_bindings (const char *undef_name
, struct link_map
*undef_map
,
883 const ElfW(Sym
) **ref
, struct sym_val
*value
,
884 const struct r_found_version
*version
, int type_class
,
887 const char *reference_name
= undef_map
->l_name
;
889 if (GLRO(dl_debug_mask
) & DL_DEBUG_BINDINGS
)
891 _dl_debug_printf ("binding file %s [%lu] to %s [%lu]: %s symbol `%s'",
894 : (rtld_progname
?: "<main program>")),
896 value
->m
->l_name
[0] ? value
->m
->l_name
: rtld_progname
,
898 protected ? "protected" : "normal", undef_name
);
900 _dl_debug_printf_c (" [%s]\n", version
->name
);
902 _dl_debug_printf_c ("\n");
905 if (GLRO(dl_debug_mask
) & DL_DEBUG_PRELINK
)
908 struct sym_val val
= { NULL
, NULL
};
910 if ((GLRO(dl_trace_prelink_map
) == NULL
911 || GLRO(dl_trace_prelink_map
) == GL(dl_ns
)[LM_ID_BASE
]._ns_loaded
)
912 && undef_map
!= GL(dl_ns
)[LM_ID_BASE
]._ns_loaded
)
914 const uint_fast32_t new_hash
= dl_new_hash (undef_name
);
915 unsigned long int old_hash
= 0xffffffff;
917 do_lookup_x (undef_name
, new_hash
, &old_hash
, *ref
, &val
,
918 undef_map
->l_local_scope
[0], 0, version
, 0, NULL
,
919 type_class
, undef_map
);
921 if (val
.s
!= value
->s
|| val
.m
!= value
->m
)
927 if (__builtin_expect (ELFW(ST_TYPE
) (value
->s
->st_info
)
930 else if (__builtin_expect (ELFW(ST_TYPE
) (value
->s
->st_info
)
931 == STT_GNU_IFUNC
, 0))
936 || GLRO(dl_trace_prelink_map
) == undef_map
937 || GLRO(dl_trace_prelink_map
) == NULL
940 _dl_printf ("%s 0x%0*Zx 0x%0*Zx -> 0x%0*Zx 0x%0*Zx ",
941 conflict
? "conflict" : "lookup",
942 (int) sizeof (ElfW(Addr
)) * 2,
943 (size_t) undef_map
->l_map_start
,
944 (int) sizeof (ElfW(Addr
)) * 2,
945 (size_t) (((ElfW(Addr
)) *ref
) - undef_map
->l_map_start
),
946 (int) sizeof (ElfW(Addr
)) * 2,
947 (size_t) (value
->s
? value
->m
->l_map_start
: 0),
948 (int) sizeof (ElfW(Addr
)) * 2,
949 (size_t) (value
->s
? value
->s
->st_value
: 0));
952 _dl_printf ("x 0x%0*Zx 0x%0*Zx ",
953 (int) sizeof (ElfW(Addr
)) * 2,
954 (size_t) (val
.s
? val
.m
->l_map_start
: 0),
955 (int) sizeof (ElfW(Addr
)) * 2,
956 (size_t) (val
.s
? val
.s
->st_value
: 0));
958 _dl_printf ("/%x %s\n", type_class
, undef_name
);