| 1 | /* Inline functions for dynamic linking. |
| 2 | Copyright (C) 1995-2023 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_STATIC_TLS_H |
| 20 | #define _DL_STATIC_TLS_H |
| 21 | |
| 22 | /* This macro is used as a callback from elf_machine_rel{a,} when a |
| 23 | static TLS reloc is about to be performed. Since (in dl-load.c) we |
| 24 | permit dynamic loading of objects that might use such relocs, we |
| 25 | have to check whether each use is actually doable. If the object |
| 26 | whose TLS segment the reference resolves to was allocated space in |
| 27 | the static TLS block at startup, then it's ok. Otherwise, we make |
| 28 | an attempt to allocate it in surplus space on the fly. If that |
| 29 | can't be done, we fall back to the error that DF_STATIC_TLS is |
| 30 | intended to produce. */ |
| 31 | #define HAVE_STATIC_TLS(map, sym_map) \ |
| 32 | (__builtin_expect ((sym_map)->l_tls_offset != NO_TLS_OFFSET \ |
| 33 | && ((sym_map)->l_tls_offset \ |
| 34 | != FORCED_DYNAMIC_TLS_OFFSET), 1)) |
| 35 | |
| 36 | #define CHECK_STATIC_TLS(map, sym_map) \ |
| 37 | do { \ |
| 38 | if (!HAVE_STATIC_TLS (map, sym_map)) \ |
| 39 | _dl_allocate_static_tls (sym_map); \ |
| 40 | } while (0) |
| 41 | |
| 42 | #define TRY_STATIC_TLS(map, sym_map) \ |
| 43 | (__builtin_expect ((sym_map)->l_tls_offset \ |
| 44 | != FORCED_DYNAMIC_TLS_OFFSET, 1) \ |
| 45 | && (__builtin_expect ((sym_map)->l_tls_offset != NO_TLS_OFFSET, 1) \ |
| 46 | || _dl_try_allocate_static_tls (sym_map, true) == 0)) |
| 47 | |
| 48 | int _dl_try_allocate_static_tls (struct link_map *map, bool optional) |
| 49 | attribute_hidden; |
| 50 | |
| 51 | #endif |
| 52 | |