]>
Commit | Line | Data |
---|---|---|
8c2e201b | 1 | /* Resolve function pointers to VDSO functions. |
d614a753 | 2 | Copyright (C) 2005-2020 Free Software Foundation, Inc. |
8c2e201b UD |
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 | |
59ba27a6 | 16 | License along with the GNU C Library; if not, see |
5a82c748 | 17 | <https://www.gnu.org/licenses/>. */ |
8c2e201b UD |
18 | |
19 | ||
b8a7c7da AZ |
20 | #ifndef _LIBC_POWERPC_VDSO_H |
21 | #define _LIBC_POWERPC_VDSO_H | |
8c2e201b | 22 | |
8ae74ead | 23 | #include <sysdep.h> |
f534255e | 24 | #include <sysdep-vdso.h> |
d400dcac | 25 | |
696caf1d | 26 | #if (defined(__PPC64__) || defined(__powerpc64__)) && _CALL_ELF != 2 |
986a5064 | 27 | # include <dl-machine.h> |
76a9b998 AZ |
28 | /* The correct solution is for _dl_vdso_vsym to return the address of the OPD |
29 | for the kernel VDSO function. That address would then be stored in the | |
30 | __vdso_* variables and returned as the result of the IFUNC resolver function. | |
31 | Yet, the kernel does not contain any OPD entries for the VDSO functions | |
32 | (incomplete implementation). However, PLT relocations for IFUNCs still expect | |
33 | the address of an OPD to be returned from the IFUNC resolver function (since | |
34 | PLT entries on PPC64 are just copies of OPDs). The solution for now is to | |
35 | create an artificial static OPD for each VDSO function returned by a resolver | |
36 | function. The TOC value is set to a non-zero value to avoid triggering lazy | |
37 | symbol resolution via .glink0/.plt0 for a zero TOC (requires thread-safe PLT | |
38 | sequences) when the dynamic linker isn't prepared for it e.g. RTLD_NOW. None | |
39 | of the kernel VDSO routines use the TOC or AUX values so any non-zero value | |
40 | will work. Note that function pointer comparisons will not use this artificial | |
41 | static OPD since those are resolved via ADDR64 relocations and will point at | |
42 | the non-IFUNC default OPD for the symbol. Lastly, because the IFUNC relocations | |
43 | are processed immediately at startup the resolver functions and this code need | |
44 | not be thread-safe, but if the caller writes to a PLT slot it must do so in a | |
45 | thread-safe manner with all the required barriers. */ | |
986a5064 | 46 | # define VDSO_IFUNC_RET(value) \ |
76a9b998 AZ |
47 | ({ \ |
48 | static Elf64_FuncDesc vdso_opd = { .fd_toc = ~0x0 }; \ | |
49 | vdso_opd.fd_func = (Elf64_Addr)value; \ | |
50 | &vdso_opd; \ | |
51 | }) | |
52 | ||
ef26eece | 53 | #else |
986a5064 AZ |
54 | # define VDSO_IFUNC_RET(value) ((void *) (value)) |
55 | #endif | |
56 | ||
8c2e201b | 57 | #endif /* _LIBC_VDSO_H */ |