1 | /* Support for STV_PROTECTED visibility. Generic version. |
2 | Copyright (C) 2021-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 | #ifndef _DL_PROTECTED_H |
20 | #define _DL_PROTECTED_H |
21 | |
22 | static inline void __attribute__ ((always_inline)) |
23 | _dl_check_protected_symbol (const char *undef_name, |
24 | const struct link_map *undef_map, |
25 | const ElfW(Sym) *ref, |
26 | const struct link_map *map, |
27 | int type_class) |
28 | { |
29 | if (undef_map == NULL || undef_map->l_type != lt_executable) |
30 | return; |
31 | |
32 | if (type_class & ELF_RTYPE_CLASS_COPY) |
33 | /* Disallow copy relocations in executable against protected |
34 | data symbols in a shared object which needs indirect external |
35 | access. */ |
36 | _dl_error_printf ("warning: copy relocation against non-copyable " |
37 | "protected symbol `%s' in `%s'\n" , |
38 | undef_name, map->l_name); |
39 | else if ((type_class & ELF_RTYPE_CLASS_PLT) && ref->st_value != 0 |
40 | && ref->st_shndx == SHN_UNDEF) |
41 | /* Disallow non-zero symbol values of undefined symbols in |
42 | executable, which are used as the function pointer, against |
43 | protected function symbols in a shared object with indirect |
44 | external access. */ |
45 | _dl_error_printf ( |
46 | "warning: direct reference to " |
47 | "protected function `%s' in `%s' may break pointer equality\n" , |
48 | undef_name, map->l_name); |
49 | else |
50 | return; |
51 | |
52 | if (map->l_1_needed & GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS) |
53 | _dl_signal_error ( |
54 | 0, map->l_name, undef_name, |
55 | N_ ("error due to GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS" )); |
56 | } |
57 | |
58 | #endif /* _DL_PROTECTED_H */ |
59 | |