1 /* Post-processing of a symbol produced by dlsym, dlvsym.
2 Copyright (C) 1999-2021 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
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/>. */
20 /* Return the link map containing the caller address. */
21 static struct link_map
*
22 _dl_sym_find_caller_link_map (ElfW(Addr
) caller
)
24 struct link_map
*l
= _dl_find_dso_for_object (caller
);
28 /* If the address is not recognized the call comes from the main
30 return GL(dl_ns
)[LM_ID_BASE
]._ns_loaded
;
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. */
37 _dl_sym_post (lookup_t result
, const ElfW(Sym
) *ref
, void *value
,
38 ElfW(Addr
) caller
, struct link_map
*match
)
40 /* Resolve indirect function address. */
41 if (__glibc_unlikely (ELFW(ST_TYPE
) (ref
->st_info
) == STT_GNU_IFUNC
))
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
);
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))
55 const char *strtab
= (const char *) D_PTR (result
,
57 /* Compute index of the symbol entry in the symbol table of
58 the DSO with the definition. */
59 unsigned int ndx
= (ref
- (ElfW(Sym
) *) D_PTR (result
,
63 match
= _dl_sym_find_caller_link_map (caller
);
65 if ((match
->l_audit_any_plt
| result
->l_audit_any_plt
) != 0)
67 unsigned int altvalue
= 0;
68 struct audit_ifaces
*afct
= GLRO(dl_audit
);
69 /* Synthesize a symbol record where the st_value field is
72 sym
.st_value
= (ElfW(Addr
)) value
;
74 for (unsigned int cnt
= 0; cnt
< GLRO(dl_naudit
); ++cnt
)
76 struct auditstate
*match_audit
77 = link_map_audit_state (match
, cnt
);
78 struct auditstate
*result_audit
79 = link_map_audit_state (result
, cnt
);
80 if (afct
->symbind
!= NULL
81 && ((match_audit
->bindflags
& LA_FLG_BINDFROM
) != 0
82 || ((result_audit
->bindflags
& LA_FLG_BINDTO
)
85 unsigned int flags
= altvalue
| LA_SYMB_DLSYM
;
87 = afct
->symbind (&sym
, ndx
,
89 &result_audit
->cookie
,
90 &flags
, strtab
+ ref
->st_name
);
91 if (new_value
!= (uintptr_t) sym
.st_value
)
93 altvalue
= LA_SYMB_ALTVALUE
;
94 sym
.st_value
= new_value
;
101 value
= (void *) sym
.st_value
;