glibc/sysdeps/unix/sysv/linux/powerpc/libc-vdso.h
Adhemerval Zanella d6d89608ac 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-14 14:52:07 -03:00

58 lines
2.8 KiB
C

/* Resolve function pointers to VDSO functions.
Copyright (C) 2005-2021 Free Software Foundation, Inc.
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 _LIBC_POWERPC_VDSO_H
#define _LIBC_POWERPC_VDSO_H
#include <sysdep.h>
#include <sysdep-vdso.h>
#if (defined(__PPC64__) || defined(__powerpc64__)) && _CALL_ELF != 2
# include <dl-funcdesc.h>
/* The correct solution is for _dl_vdso_vsym to return the address of the OPD
for the kernel VDSO function. That address would then be stored in the
__vdso_* variables and returned as the result of the IFUNC resolver function.
Yet, the kernel does not contain any OPD entries for the VDSO functions
(incomplete implementation). However, PLT relocations for IFUNCs still expect
the address of an OPD to be returned from the IFUNC resolver function (since
PLT entries on PPC64 are just copies of OPDs). The solution for now is to
create an artificial static OPD for each VDSO function returned by a resolver
function. The TOC value is set to a non-zero value to avoid triggering lazy
symbol resolution via .glink0/.plt0 for a zero TOC (requires thread-safe PLT
sequences) when the dynamic linker isn't prepared for it e.g. RTLD_NOW. None
of the kernel VDSO routines use the TOC or AUX values so any non-zero value
will work. Note that function pointer comparisons will not use this artificial
static OPD since those are resolved via ADDR64 relocations and will point at
the non-IFUNC default OPD for the symbol. Lastly, because the IFUNC relocations
are processed immediately at startup the resolver functions and this code need
not be thread-safe, but if the caller writes to a PLT slot it must do so in a
thread-safe manner with all the required barriers. */
# define VDSO_IFUNC_RET(value) \
({ \
static Elf64_FuncDesc vdso_opd = { .fd_toc = ~0x0 }; \
vdso_opd.fd_func = (Elf64_Addr)value; \
&vdso_opd; \
})
#else
# define VDSO_IFUNC_RET(value) ((void *) (value))
#endif
#endif /* _LIBC_VDSO_H */