glibc/sysdeps/unix/sysv/linux/powerpc/powerpc64/ldsodefs.h
Ulrich Weigand 696caf1d00 PowerPC64 ELFv2 ABI 2/6: Remove function descriptors
This patch adds support for the ELFv2 ABI feature to remove function
descriptors.  See this GCC patch for in-depth discussion:
http://gcc.gnu.org/ml/gcc-patches/2013-11/msg01141.html

This mostly involves two types of changes: updating assembler source
files to the new logic, and updating the dynamic loader.

After the refactoring in the previous patch, most of the assembler source
changes can be handled simply by providing ELFv2 versions of the
macros in sysdep.h.   One somewhat non-obvious change is in __GI__setjmp:
this used to "fall through" to the immediately following __setjmp ENTRY
point.  This is no longer safe in the ELFv2 since ENTRY defines both
a global and a local entry point, and you cannot simply fall through
to a global entry point as it requires r12 to be set up.

Also, makecontext needs to be updated to set up registers according to
the new ABI for calling into the context's start routine.

The dynamic linker changes mostly consist of removing special code
to handle function descriptors.  We also need to support the new PLT
and glink format used by the the ELFv2 linker, see:
https://sourceware.org/ml/binutils/2013-10/msg00376.html

In addition, the dynamic linker now verifies that the dynamic libraries
it loads match its own ABI.

The hack in VDSO_IFUNC_RET to "synthesize" a function descriptor
for vDSO routines is also no longer necessary for ELFv2.
2013-12-04 07:41:38 -06:00

81 lines
2.5 KiB
C

/* Run-time dynamic linker data structures for loaded ELF shared objects.
Copyright (C) 2005-2013 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
<http://www.gnu.org/licenses/>. */
#ifndef _LDSODEFS_H
/* Get the real definitions. */
#include_next <ldsodefs.h>
/* Now define our stuff. */
#if _CALL_ELF != 2
static __always_inline bool
_dl_ppc64_is_opd_sym (const struct link_map *l, const ElfW(Sym) *sym)
{
return (ELFW(ST_TYPE) (sym->st_info) == STT_FUNC
&& l->l_addr + sym->st_value >= (ElfW(Addr)) l->l_ld
&& l->l_addr + sym->st_value < l->l_map_end
&& sym->st_size != 0);
}
static __always_inline bool
_dl_ppc64_addr_sym_match (const struct link_map *l, const ElfW(Sym) *sym,
const ElfW(Sym) *matchsym, ElfW(Addr) addr)
{
ElfW(Addr) value = l->l_addr + sym->st_value;
if (_dl_ppc64_is_opd_sym (l, sym))
{
if (addr < value || addr >= value + 24)
{
value = *(ElfW(Addr) *) value;
if (addr < value || addr >= value + sym->st_size)
return false;
}
}
else if (sym->st_shndx == SHN_UNDEF || sym->st_size == 0)
{
if (addr != value)
return false;
}
else if (addr < value || addr >= value + sym->st_size)
return false;
if (matchsym == NULL)
return true;
ElfW(Addr) matchvalue = l->l_addr + matchsym->st_value;
if (_dl_ppc64_is_opd_sym (l, matchsym)
&& (addr < matchvalue || addr > matchvalue + 24))
matchvalue = *(ElfW(Addr) *) matchvalue;
return matchvalue < value;
}
/* If this is a function symbol defined past the end of our dynamic
section, then it must be a function descriptor. Allow these symbols
to match their associated function code range as well as the
descriptor addresses. */
#undef DL_ADDR_SYM_MATCH
#define DL_ADDR_SYM_MATCH(L, SYM, MATCHSYM, ADDR) \
_dl_ppc64_addr_sym_match (L, SYM, MATCHSYM, ADDR)
#endif
#endif /* ldsodefs.h */