elf: Fix dynamic-link.h usage on rtld.c
The 4af6982e4c fix does not fully handle RTLD_BOOTSTRAP usage on
rtld.c due two issues:
1. RTLD_BOOTSTRAP is also used on dl-machine.h on various
architectures and it changes the semantics of various machine
relocation functions.
2. The elf_get_dynamic_info() change was done sideways, previously
to 490e6c62aa get-dynamic-info.h was included by the first
dynamic-link.h include *without* RTLD_BOOTSTRAP being defined.
It means that the code within elf_get_dynamic_info() that uses
RTLD_BOOTSTRAP is in fact unused.
To fix 1. this patch now includes dynamic-link.h only once with
RTLD_BOOTSTRAP defined. The ELF_DYNAMIC_RELOCATE call will now have
the relocation fnctions with the expected semantics for the loader.
And to fix 2. part of 4af6982e4c is reverted (the check argument
elf_get_dynamic_info() is not required) and the RTLD_BOOTSTRAP
pieces are removed.
To reorganize the includes the static TLS definition is moved to
its own header to avoid a circular dependency (it is defined on
dynamic-link.h and dl-machine.h requires it at same time other
dynamic-link.h definition requires dl-machine.h defitions).
Also ELF_MACHINE_NO_REL, ELF_MACHINE_NO_RELA, and ELF_MACHINE_PLT_REL
are moved to its own header. Only ancient ABIs need special values
(arm, i386, and mips), so a generic one is used as default.
The powerpc Elf64_FuncDesc is also moved to its own header, since
csu code required its definition (which would require either include
elf/ folder or add a full path with elf/).
Checked on x86_64, i686, aarch64, armhf, powerpc64, powerpc32,
and powerpc64le.
Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
2021-10-13 12:49:34 +00:00
|
|
|
/* Inline functions for dynamic linking.
|
2022-01-01 18:54:23 +00:00
|
|
|
Copyright (C) 1995-2022 Free Software Foundation, Inc.
|
elf: Fix dynamic-link.h usage on rtld.c
The 4af6982e4c fix does not fully handle RTLD_BOOTSTRAP usage on
rtld.c due two issues:
1. RTLD_BOOTSTRAP is also used on dl-machine.h on various
architectures and it changes the semantics of various machine
relocation functions.
2. The elf_get_dynamic_info() change was done sideways, previously
to 490e6c62aa get-dynamic-info.h was included by the first
dynamic-link.h include *without* RTLD_BOOTSTRAP being defined.
It means that the code within elf_get_dynamic_info() that uses
RTLD_BOOTSTRAP is in fact unused.
To fix 1. this patch now includes dynamic-link.h only once with
RTLD_BOOTSTRAP defined. The ELF_DYNAMIC_RELOCATE call will now have
the relocation fnctions with the expected semantics for the loader.
And to fix 2. part of 4af6982e4c is reverted (the check argument
elf_get_dynamic_info() is not required) and the RTLD_BOOTSTRAP
pieces are removed.
To reorganize the includes the static TLS definition is moved to
its own header to avoid a circular dependency (it is defined on
dynamic-link.h and dl-machine.h requires it at same time other
dynamic-link.h definition requires dl-machine.h defitions).
Also ELF_MACHINE_NO_REL, ELF_MACHINE_NO_RELA, and ELF_MACHINE_PLT_REL
are moved to its own header. Only ancient ABIs need special values
(arm, i386, and mips), so a generic one is used as default.
The powerpc Elf64_FuncDesc is also moved to its own header, since
csu code required its definition (which would require either include
elf/ folder or add a full path with elf/).
Checked on x86_64, i686, aarch64, armhf, powerpc64, powerpc32,
and powerpc64le.
Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
2021-10-13 12:49:34 +00:00
|
|
|
This file is part of the GNU C Library.
|
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with the GNU C Library; if not, see
|
|
|
|
<https://www.gnu.org/licenses/>. */
|
|
|
|
|
|
|
|
#ifndef _DL_STATIC_TLS_H
|
|
|
|
#define _DL_STATIC_TLS_H
|
|
|
|
|
|
|
|
/* This macro is used as a callback from elf_machine_rel{a,} when a
|
|
|
|
static TLS reloc is about to be performed. Since (in dl-load.c) we
|
|
|
|
permit dynamic loading of objects that might use such relocs, we
|
|
|
|
have to check whether each use is actually doable. If the object
|
|
|
|
whose TLS segment the reference resolves to was allocated space in
|
|
|
|
the static TLS block at startup, then it's ok. Otherwise, we make
|
|
|
|
an attempt to allocate it in surplus space on the fly. If that
|
|
|
|
can't be done, we fall back to the error that DF_STATIC_TLS is
|
|
|
|
intended to produce. */
|
|
|
|
#define HAVE_STATIC_TLS(map, sym_map) \
|
|
|
|
(__builtin_expect ((sym_map)->l_tls_offset != NO_TLS_OFFSET \
|
|
|
|
&& ((sym_map)->l_tls_offset \
|
|
|
|
!= FORCED_DYNAMIC_TLS_OFFSET), 1))
|
|
|
|
|
|
|
|
#define CHECK_STATIC_TLS(map, sym_map) \
|
|
|
|
do { \
|
|
|
|
if (!HAVE_STATIC_TLS (map, sym_map)) \
|
|
|
|
_dl_allocate_static_tls (sym_map); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define TRY_STATIC_TLS(map, sym_map) \
|
|
|
|
(__builtin_expect ((sym_map)->l_tls_offset \
|
|
|
|
!= FORCED_DYNAMIC_TLS_OFFSET, 1) \
|
|
|
|
&& (__builtin_expect ((sym_map)->l_tls_offset != NO_TLS_OFFSET, 1) \
|
|
|
|
|| _dl_try_allocate_static_tls (sym_map, true) == 0))
|
|
|
|
|
|
|
|
int _dl_try_allocate_static_tls (struct link_map *map, bool optional)
|
|
|
|
attribute_hidden;
|
|
|
|
|
|
|
|
#endif
|