1/* Post-processing of a symbol produced by dlsym, dlvsym.
2 Copyright (C) 1999-2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19
20/* Return the link map containing the caller address. */
21static struct link_map *
22_dl_sym_find_caller_link_map (ElfW(Addr) caller)
23{
24 struct link_map *l = _dl_find_dso_for_object (caller);
25 if (l != NULL)
26 return l;
27 else
28 /* If the address is not recognized the call comes from the main
29 program (we hope). */
30 return GL(dl_ns)[LM_ID_BASE]._ns_loaded;
31}
32
33/* Translates RESULT, *REF, VALUE into a symbol address from the point
34 of view of MATCH. Performs IFUNC resolution and auditing if
35 necessary. If MATCH is NULL, CALLER is used to determine it. */
36static void *
37_dl_sym_post (lookup_t result, const ElfW(Sym) *ref, void *value,
38 ElfW(Addr) caller, struct link_map *match)
39{
40 /* Resolve indirect function address. */
41 if (__glibc_unlikely (ELFW(ST_TYPE) (ref->st_info) == STT_GNU_IFUNC))
42 {
43 DL_FIXUP_VALUE_TYPE fixup
44 = DL_FIXUP_MAKE_VALUE (result, (ElfW(Addr)) value);
45 fixup = elf_ifunc_invoke (DL_FIXUP_VALUE_ADDR (fixup));
46 value = (void *) DL_FIXUP_VALUE_CODE_ADDR (fixup);
47 }
48
49#ifdef SHARED
50 /* Auditing checkpoint: we have a new binding. Provide the
51 auditing libraries the possibility to change the value and
52 tell us whether further auditing is wanted. */
53 if (__glibc_unlikely (GLRO(dl_naudit) > 0))
54 {
55 if (match == NULL)
56 match = _dl_sym_find_caller_link_map (caller);
57 _dl_audit_symbind_alt (match, ref, &value, result);
58 }
59#endif
60 return value;
61}
62

source code of glibc/elf/dl-sym-post.h