2000-10-15 03:20:01 +00:00
|
|
|
/* Machine-dependent ELF dynamic relocation inline functions. PA-RISC version.
|
2023-01-06 21:08:04 +00:00
|
|
|
Copyright (C) 1995-2023 Free Software Foundation, Inc.
|
2000-10-15 03:20:01 +00:00
|
|
|
This file is part of the GNU C Library.
|
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
2001-07-06 04:56:23 +00:00
|
|
|
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.
|
2000-10-15 03:20:01 +00:00
|
|
|
|
|
|
|
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
|
2001-07-06 04:56:23 +00:00
|
|
|
Lesser General Public License for more details.
|
2000-10-15 03:20:01 +00:00
|
|
|
|
2001-07-06 04:56:23 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2012-03-09 23:56:38 +00:00
|
|
|
License along with the GNU C Library. If not, see
|
Prefer https to http for gnu.org and fsf.org URLs
Also, change sources.redhat.com to sourceware.org.
This patch was automatically generated by running the following shell
script, which uses GNU sed, and which avoids modifying files imported
from upstream:
sed -ri '
s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g
s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g
' \
$(find $(git ls-files) -prune -type f \
! -name '*.po' \
! -name 'ChangeLog*' \
! -path COPYING ! -path COPYING.LIB \
! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \
! -path manual/texinfo.tex ! -path scripts/config.guess \
! -path scripts/config.sub ! -path scripts/install-sh \
! -path scripts/mkinstalldirs ! -path scripts/move-if-change \
! -path INSTALL ! -path locale/programs/charmap-kw.h \
! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \
! '(' -name configure \
-execdir test -f configure.ac -o -f configure.in ';' ')' \
! '(' -name preconfigure \
-execdir test -f preconfigure.ac ';' ')' \
-print)
and then by running 'make dist-prepare' to regenerate files built
from the altered files, and then executing the following to cleanup:
chmod a+x sysdeps/unix/sysv/linux/riscv/configure
# Omit irrelevant whitespace and comment-only changes,
# perhaps from a slightly-different Autoconf version.
git checkout -f \
sysdeps/csky/configure \
sysdeps/hppa/configure \
sysdeps/riscv/configure \
sysdeps/unix/sysv/linux/csky/configure
# Omit changes that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines
git checkout -f \
sysdeps/powerpc/powerpc64/ppc-mcount.S \
sysdeps/unix/sysv/linux/s390/s390-64/syscall.S
# Omit change that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline
git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
2019-09-07 05:40:42 +00:00
|
|
|
<https://www.gnu.org/licenses/>. */
|
2000-10-15 03:20:01 +00:00
|
|
|
|
|
|
|
#ifndef dl_machine_h
|
|
|
|
#define dl_machine_h 1
|
|
|
|
|
|
|
|
#define ELF_MACHINE_NAME "hppa"
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
2004-04-17 22:53:29 +00:00
|
|
|
#include <assert.h>
|
2000-10-15 03:20:01 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <link.h>
|
2004-04-17 22:53:29 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <dl-fptr.h>
|
|
|
|
#include <abort-instr.h>
|
2006-05-15 Carlos O'Donell <carlos@systemhalted.org>
* sysdeps/hppa/dl-machine.h: Include tls.h
(elf_machine_fixup_plt): Returns fdesc.
(elf_machine_profile_fixup_plt): Remove.
(elf_machine_plt_value): Returns fdesc.
(elf_machine_runtime_setup): Check that dl_profile != NULL.
(ARCH_LA_PLTENT, ARCH_LA_PLTEXIT): Define.
(RTLD_START): Use iitlbp with sr0.
(elf_machine_type_class): Include TLS relocs.
(reassemble_21, reassemble_14): Define.
(elf_machine_rela): Add DIR21L, DIR14R, PLABEL21L, PLABEL14R,
TLS_DTPMOD32, TLS_TPREL32, TLS_DTPOFF32 support.
(TRAMPOLINE_TEMPLATE): Move to ...
* sysdeps/hppa/dl-trampoline.S: ... here.
* sysdeps/hppa/abort-instr.h: Use iitlbp with sr0.
* sysdeps/hppa/dl-lookupcfg.h: Inlcude dl-fptr.h.
(DL_FIXUP_VALUE_TYPE, DL_FIXUP_MAKE_VALUE, DL_FIXUP_VALUE_CODE_ADDR,
DL_FIXUP_VALUE_ADD, DL_FIXUP_ADDR_VALUE): Define.
* sysdeps/hppa/sysdep.h: Use "!" as a separator. Cleanup comments.
* sysdeps/hppa/bits/link.h (La_hppa_regs, La_hppa_retval): Define.
Define prototypes for la_hppa_gnu_pltenter and la_hppa_gnu_pltexit.
2006-05-14 23:54:47 +00:00
|
|
|
#include <tls.h>
|
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
|
|
|
#include <dl-static-tls.h>
|
|
|
|
#include <dl-machine-rel.h>
|
2004-04-17 22:53:29 +00:00
|
|
|
|
2011-10-05 09:52:45 +00:00
|
|
|
/* These two definitions must match the definition of the stub in
|
2004-04-17 22:53:29 +00:00
|
|
|
bfd/elf32-hppa.c (see plt_stub[]).
|
2011-10-05 09:52:45 +00:00
|
|
|
|
2004-04-17 22:53:29 +00:00
|
|
|
a. Define the size of the *entire* stub we place at the end of the PLT
|
|
|
|
table (right up against the GOT).
|
2011-10-05 09:52:45 +00:00
|
|
|
|
2004-04-17 22:53:29 +00:00
|
|
|
b. Define the number of bytes back from the GOT to the entry point of
|
|
|
|
the PLT stub. You see the PLT stub must be entered in the middle
|
2011-10-05 09:52:45 +00:00
|
|
|
so it can depwi to find it's own address (long jump stub)
|
|
|
|
|
2004-04-17 22:53:29 +00:00
|
|
|
c. Define the size of a single PLT entry so we can jump over the
|
|
|
|
last entry to get the stub address */
|
2011-10-05 09:52:45 +00:00
|
|
|
|
2004-04-17 22:53:29 +00:00
|
|
|
#define SIZEOF_PLT_STUB (7*4)
|
2000-10-15 03:20:01 +00:00
|
|
|
#define GOT_FROM_PLT_STUB (4*4)
|
2004-04-17 22:53:29 +00:00
|
|
|
#define PLT_ENTRY_SIZE (2*4)
|
2000-10-15 03:20:01 +00:00
|
|
|
|
Fix data race in setting function descriptors during lazy binding on hppa.
This addresses an issue that is present mainly on SMP machines running
threaded code. In a typical indirect call or PLT import stub, the
target address is loaded first. Then the global pointer is loaded into
the PIC register in the delay slot of a branch to the target address.
During lazy binding, the target address is a trampoline which transfers
to _dl_runtime_resolve().
_dl_runtime_resolve() uses the relocation offset stored in the global
pointer and the linkage map stored in the trampoline to find the
relocation. Then, the function descriptor is updated.
In a multi-threaded application, it is possible for the global pointer
to be updated between the load of the target address and the global
pointer. When this happens, the relocation offset has been replaced
by the new global pointer. The function pointer has probably been
updated as well but there is no way to find the address of the function
descriptor and to transfer to the target. So, _dl_runtime_resolve()
typically crashes.
HP-UX addressed this problem by adding an extra pc-relative branch to
the trampoline. The descriptor is initially setup to point to the
branch. The branch then transfers to the trampoline. This allowed
the trampoline code to figure out which descriptor was being used
without any modification to user code. I didn't use this approach
as it is more complex and changes function pointer canonicalization.
The order of loading the target address and global pointer in
indirect calls was not consistent with the order used in import stubs.
In particular, $$dyncall and some inline versions of it loaded the
global pointer first. This was inconsistent with the global pointer
being updated first in dl-machine.h. Assuming the accesses are
ordered, we want elf_machine_fixup_plt() to store the global pointer
first and calls to load it last. Then, the global pointer will be
correct when the target function is entered.
However, just to make things more fun, HP added support for
out-of-order execution of accesses in PA 2.0. The accesses used by
calls are weakly ordered. So, it's possibly under some circumstances
that a function might be entered with the wrong global pointer.
However, HP uses weakly ordered accesses in 64-bit HP-UX, so I assume
that loading the global pointer in the delay slot of the branch must
work consistently.
The basic fix for the race is a combination of modifying user code to
preserve the address of the function descriptor in register %r22 and
setting the least-significant bit in the relocation offset. The
latter was suggested by Carlos as a way to distinguish relocation
offsets from global pointer values. Conventionally, %r22 is used
as the address of the function descriptor in calls to $$dyncall.
So, it wasn't hard to preserve the address in %r22.
I have updated gcc trunk and gcc-9 branch to not clobber %r22 in
$$dyncall and inline indirect calls. I have also modified the import
stubs in binutils trunk and the 2.33 branch to preserve %r22. This
required making the stubs one instruction longer but we save one
relocation. I also modified binutils to align the .plt section on
a 8-byte boundary. This allows descriptors to be updated atomically
with a floting-point store.
With these changes, _dl_runtime_resolve() can fallback to an alternate
mechanism to find the relocation offset when it has been clobbered.
There's just one additional instruction in the fast path. I tested
the fallback function, _dl_fix_reloc_arg(), by changing the branch to
always use the fallback. Old code still runs as it did before.
Fixes bug 23296.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2020-03-30 20:36:49 +00:00
|
|
|
/* The gp slot in the function descriptor contains the relocation offset
|
|
|
|
before resolution. To distinguish between a resolved gp value and an
|
|
|
|
unresolved relocation offset we set an unused bit in the relocation
|
|
|
|
offset. This would allow us to do a synchronzied two word update
|
|
|
|
using this bit (interlocked update), but instead of waiting for the
|
|
|
|
update we simply recompute the gp value given that we know the ip. */
|
|
|
|
#define PA_GP_RELOC 1
|
|
|
|
|
2004-04-17 22:53:29 +00:00
|
|
|
/* Initialize the function descriptor table before relocations */
|
|
|
|
static inline void
|
|
|
|
__hppa_init_bootstrap_fdesc_table (struct link_map *map)
|
2000-10-15 03:20:01 +00:00
|
|
|
{
|
2004-04-17 22:53:29 +00:00
|
|
|
ElfW(Addr) *boot_table;
|
|
|
|
|
|
|
|
/* Careful: this will be called before got has been relocated... */
|
|
|
|
ELF_MACHINE_LOAD_ADDRESS(boot_table,_dl_boot_fptr_table);
|
2000-10-15 03:20:01 +00:00
|
|
|
|
2004-04-17 22:53:29 +00:00
|
|
|
map->l_mach.fptr_table_len = ELF_MACHINE_BOOT_FPTR_TABLE_LEN;
|
|
|
|
map->l_mach.fptr_table = boot_table;
|
|
|
|
}
|
2000-10-15 03:20:01 +00:00
|
|
|
|
elf: Avoid nested functions in the loader [BZ #27220]
dynamic-link.h is included more than once in some elf/ files (rtld.c,
dl-conflict.c, dl-reloc.c, dl-reloc-static-pie.c) and uses GCC nested
functions. This harms readability and the nested functions usage
is the biggest obstacle prevents Clang build (Clang doesn't support GCC
nested functions).
The key idea for unnesting is to add extra parameters (struct link_map
*and struct r_scope_elm *[]) to RESOLVE_MAP,
ELF_MACHINE_BEFORE_RTLD_RELOC, ELF_DYNAMIC_RELOCATE, elf_machine_rel[a],
elf_machine_lazy_rel, and elf_machine_runtime_setup. (This is inspired
by Stan Shebs' ppc64/x86-64 implementation in the
google/grte/v5-2.27/master which uses mixed extra parameters and static
variables.)
Future simplification:
* If mips elf_machine_runtime_setup no longer needs RESOLVE_GOTSYM,
elf_machine_runtime_setup can drop the `scope` parameter.
* If TLSDESC no longer need to be in elf_machine_lazy_rel,
elf_machine_lazy_rel can drop the `scope` parameter.
Tested on aarch64, i386, x86-64, powerpc64le, powerpc64, powerpc32,
sparc64, sparcv9, s390x, s390, hppa, ia64, armhf, alpha, and mips64.
In addition, tested build-many-glibcs.py with {arc,csky,microblaze,nios2}-linux-gnu
and riscv64-linux-gnu-rv64imafdc-lp64d.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-10-07 18:55:02 +00:00
|
|
|
#define ELF_MACHINE_BEFORE_RTLD_RELOC(map, dynamic_info) \
|
|
|
|
__hppa_init_bootstrap_fdesc_table (map); \
|
2012-04-17 03:46:34 +00:00
|
|
|
_dl_fptr_init();
|
2000-10-15 03:20:01 +00:00
|
|
|
|
2000-10-20 17:04:28 +00:00
|
|
|
/* Return nonzero iff ELF header is compatible with the running host. */
|
2000-10-15 03:20:01 +00:00
|
|
|
static inline int
|
2000-10-20 17:04:28 +00:00
|
|
|
elf_machine_matches_host (const Elf32_Ehdr *ehdr)
|
2000-10-15 03:20:01 +00:00
|
|
|
{
|
2000-10-20 17:04:28 +00:00
|
|
|
return ehdr->e_machine == EM_PARISC;
|
2000-10-15 03:20:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the link-time address of _DYNAMIC. */
|
2004-04-17 22:53:29 +00:00
|
|
|
static inline Elf32_Addr
|
|
|
|
elf_machine_dynamic (void) __attribute__ ((const));
|
|
|
|
|
2000-10-15 03:20:01 +00:00
|
|
|
static inline Elf32_Addr
|
|
|
|
elf_machine_dynamic (void)
|
|
|
|
{
|
|
|
|
Elf32_Addr dynamic;
|
|
|
|
|
2017-12-02 16:04:16 +00:00
|
|
|
asm ("bl 1f,%0\n"
|
|
|
|
" addil L'_GLOBAL_OFFSET_TABLE_ - ($PIC_pcrel$0 - 1),%0\n"
|
|
|
|
"1: ldw R'_GLOBAL_OFFSET_TABLE_ - ($PIC_pcrel$0 - 5)(%%r1),%0\n"
|
2004-04-17 22:53:29 +00:00
|
|
|
: "=r" (dynamic) : : "r1");
|
2000-10-15 03:20:01 +00:00
|
|
|
|
|
|
|
return dynamic;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the run-time load address of the shared object. */
|
2004-04-17 22:53:29 +00:00
|
|
|
static inline Elf32_Addr
|
|
|
|
elf_machine_load_address (void) __attribute__ ((const));
|
|
|
|
|
2000-10-15 03:20:01 +00:00
|
|
|
static inline Elf32_Addr
|
|
|
|
elf_machine_load_address (void)
|
|
|
|
{
|
2004-04-17 22:53:29 +00:00
|
|
|
Elf32_Addr dynamic;
|
2000-10-15 03:20:01 +00:00
|
|
|
|
2001-06-06 11:52:59 +00:00
|
|
|
asm (
|
2017-12-02 16:04:16 +00:00
|
|
|
" bl 1f,%0\n"
|
|
|
|
" addil L'_DYNAMIC - ($PIC_pcrel$0 - 1),%0\n"
|
|
|
|
"1: ldo R'_DYNAMIC - ($PIC_pcrel$0 - 5)(%%r1),%0\n"
|
2004-04-17 22:53:29 +00:00
|
|
|
: "=r" (dynamic) : : "r1");
|
2000-10-15 03:20:01 +00:00
|
|
|
|
2004-04-17 22:53:29 +00:00
|
|
|
return dynamic - elf_machine_dynamic ();
|
2000-10-15 03:20:01 +00:00
|
|
|
}
|
|
|
|
|
2011-10-05 09:52:45 +00:00
|
|
|
/* Fixup a PLT entry to bounce directly to the function at VALUE. */
|
|
|
|
static inline struct fdesc __attribute__ ((always_inline))
|
2000-10-15 03:20:01 +00:00
|
|
|
elf_machine_fixup_plt (struct link_map *map, lookup_t t,
|
2017-06-14 01:17:25 +00:00
|
|
|
const ElfW(Sym) *refsym, const ElfW(Sym) *sym,
|
2000-10-15 03:20:01 +00:00
|
|
|
const Elf32_Rela *reloc,
|
2006-05-15 Carlos O'Donell <carlos@systemhalted.org>
* sysdeps/hppa/dl-machine.h: Include tls.h
(elf_machine_fixup_plt): Returns fdesc.
(elf_machine_profile_fixup_plt): Remove.
(elf_machine_plt_value): Returns fdesc.
(elf_machine_runtime_setup): Check that dl_profile != NULL.
(ARCH_LA_PLTENT, ARCH_LA_PLTEXIT): Define.
(RTLD_START): Use iitlbp with sr0.
(elf_machine_type_class): Include TLS relocs.
(reassemble_21, reassemble_14): Define.
(elf_machine_rela): Add DIR21L, DIR14R, PLABEL21L, PLABEL14R,
TLS_DTPMOD32, TLS_TPREL32, TLS_DTPOFF32 support.
(TRAMPOLINE_TEMPLATE): Move to ...
* sysdeps/hppa/dl-trampoline.S: ... here.
* sysdeps/hppa/abort-instr.h: Use iitlbp with sr0.
* sysdeps/hppa/dl-lookupcfg.h: Inlcude dl-fptr.h.
(DL_FIXUP_VALUE_TYPE, DL_FIXUP_MAKE_VALUE, DL_FIXUP_VALUE_CODE_ADDR,
DL_FIXUP_VALUE_ADD, DL_FIXUP_ADDR_VALUE): Define.
* sysdeps/hppa/sysdep.h: Use "!" as a separator. Cleanup comments.
* sysdeps/hppa/bits/link.h (La_hppa_regs, La_hppa_retval): Define.
Define prototypes for la_hppa_gnu_pltenter and la_hppa_gnu_pltexit.
2006-05-14 23:54:47 +00:00
|
|
|
Elf32_Addr *reloc_addr, struct fdesc value)
|
2000-10-15 03:20:01 +00:00
|
|
|
{
|
2006-09-07 16:34:43 +00:00
|
|
|
volatile Elf32_Addr *rfdesc = reloc_addr;
|
2004-04-17 22:53:29 +00:00
|
|
|
/* map is the link_map for the caller, t is the link_map for the object
|
|
|
|
being called */
|
Fix data race in setting function descriptors during lazy binding on hppa.
This addresses an issue that is present mainly on SMP machines running
threaded code. In a typical indirect call or PLT import stub, the
target address is loaded first. Then the global pointer is loaded into
the PIC register in the delay slot of a branch to the target address.
During lazy binding, the target address is a trampoline which transfers
to _dl_runtime_resolve().
_dl_runtime_resolve() uses the relocation offset stored in the global
pointer and the linkage map stored in the trampoline to find the
relocation. Then, the function descriptor is updated.
In a multi-threaded application, it is possible for the global pointer
to be updated between the load of the target address and the global
pointer. When this happens, the relocation offset has been replaced
by the new global pointer. The function pointer has probably been
updated as well but there is no way to find the address of the function
descriptor and to transfer to the target. So, _dl_runtime_resolve()
typically crashes.
HP-UX addressed this problem by adding an extra pc-relative branch to
the trampoline. The descriptor is initially setup to point to the
branch. The branch then transfers to the trampoline. This allowed
the trampoline code to figure out which descriptor was being used
without any modification to user code. I didn't use this approach
as it is more complex and changes function pointer canonicalization.
The order of loading the target address and global pointer in
indirect calls was not consistent with the order used in import stubs.
In particular, $$dyncall and some inline versions of it loaded the
global pointer first. This was inconsistent with the global pointer
being updated first in dl-machine.h. Assuming the accesses are
ordered, we want elf_machine_fixup_plt() to store the global pointer
first and calls to load it last. Then, the global pointer will be
correct when the target function is entered.
However, just to make things more fun, HP added support for
out-of-order execution of accesses in PA 2.0. The accesses used by
calls are weakly ordered. So, it's possibly under some circumstances
that a function might be entered with the wrong global pointer.
However, HP uses weakly ordered accesses in 64-bit HP-UX, so I assume
that loading the global pointer in the delay slot of the branch must
work consistently.
The basic fix for the race is a combination of modifying user code to
preserve the address of the function descriptor in register %r22 and
setting the least-significant bit in the relocation offset. The
latter was suggested by Carlos as a way to distinguish relocation
offsets from global pointer values. Conventionally, %r22 is used
as the address of the function descriptor in calls to $$dyncall.
So, it wasn't hard to preserve the address in %r22.
I have updated gcc trunk and gcc-9 branch to not clobber %r22 in
$$dyncall and inline indirect calls. I have also modified the import
stubs in binutils trunk and the 2.33 branch to preserve %r22. This
required making the stubs one instruction longer but we save one
relocation. I also modified binutils to align the .plt section on
a 8-byte boundary. This allows descriptors to be updated atomically
with a floting-point store.
With these changes, _dl_runtime_resolve() can fallback to an alternate
mechanism to find the relocation offset when it has been clobbered.
There's just one additional instruction in the fast path. I tested
the fallback function, _dl_fix_reloc_arg(), by changing the branch to
always use the fallback. Old code still runs as it did before.
Fixes bug 23296.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2020-03-30 20:36:49 +00:00
|
|
|
|
|
|
|
/* We would like the function descriptor to be double word aligned. This
|
|
|
|
helps performance (ip and gp then reside on the same cache line) and
|
|
|
|
we can update the pair atomically with a single store. The linker
|
|
|
|
now ensures this alignment but we still have to handle old code. */
|
|
|
|
if ((unsigned int)reloc_addr & 7)
|
|
|
|
{
|
|
|
|
/* Need to ensure that the gp is visible before the code
|
|
|
|
entry point is updated */
|
|
|
|
rfdesc[1] = value.gp;
|
|
|
|
atomic_full_barrier();
|
|
|
|
rfdesc[0] = value.ip;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Update pair atomically with floating point store. */
|
|
|
|
union { ElfW(Word) v[2]; double d; } u;
|
|
|
|
|
|
|
|
u.v[0] = value.ip;
|
|
|
|
u.v[1] = value.gp;
|
|
|
|
*(volatile double *)rfdesc = u.d;
|
|
|
|
}
|
2006-05-15 Carlos O'Donell <carlos@systemhalted.org>
* sysdeps/hppa/dl-machine.h: Include tls.h
(elf_machine_fixup_plt): Returns fdesc.
(elf_machine_profile_fixup_plt): Remove.
(elf_machine_plt_value): Returns fdesc.
(elf_machine_runtime_setup): Check that dl_profile != NULL.
(ARCH_LA_PLTENT, ARCH_LA_PLTEXIT): Define.
(RTLD_START): Use iitlbp with sr0.
(elf_machine_type_class): Include TLS relocs.
(reassemble_21, reassemble_14): Define.
(elf_machine_rela): Add DIR21L, DIR14R, PLABEL21L, PLABEL14R,
TLS_DTPMOD32, TLS_TPREL32, TLS_DTPOFF32 support.
(TRAMPOLINE_TEMPLATE): Move to ...
* sysdeps/hppa/dl-trampoline.S: ... here.
* sysdeps/hppa/abort-instr.h: Use iitlbp with sr0.
* sysdeps/hppa/dl-lookupcfg.h: Inlcude dl-fptr.h.
(DL_FIXUP_VALUE_TYPE, DL_FIXUP_MAKE_VALUE, DL_FIXUP_VALUE_CODE_ADDR,
DL_FIXUP_VALUE_ADD, DL_FIXUP_ADDR_VALUE): Define.
* sysdeps/hppa/sysdep.h: Use "!" as a separator. Cleanup comments.
* sysdeps/hppa/bits/link.h (La_hppa_regs, La_hppa_retval): Define.
Define prototypes for la_hppa_gnu_pltenter and la_hppa_gnu_pltexit.
2006-05-14 23:54:47 +00:00
|
|
|
return value;
|
2004-04-17 22:53:29 +00:00
|
|
|
}
|
|
|
|
|
2000-10-15 03:20:01 +00:00
|
|
|
/* Return the final value of a plt relocation. */
|
2011-10-05 09:52:45 +00:00
|
|
|
static inline struct fdesc
|
2000-10-15 03:20:01 +00:00
|
|
|
elf_machine_plt_value (struct link_map *map, const Elf32_Rela *reloc,
|
2006-05-15 Carlos O'Donell <carlos@systemhalted.org>
* sysdeps/hppa/dl-machine.h: Include tls.h
(elf_machine_fixup_plt): Returns fdesc.
(elf_machine_profile_fixup_plt): Remove.
(elf_machine_plt_value): Returns fdesc.
(elf_machine_runtime_setup): Check that dl_profile != NULL.
(ARCH_LA_PLTENT, ARCH_LA_PLTEXIT): Define.
(RTLD_START): Use iitlbp with sr0.
(elf_machine_type_class): Include TLS relocs.
(reassemble_21, reassemble_14): Define.
(elf_machine_rela): Add DIR21L, DIR14R, PLABEL21L, PLABEL14R,
TLS_DTPMOD32, TLS_TPREL32, TLS_DTPOFF32 support.
(TRAMPOLINE_TEMPLATE): Move to ...
* sysdeps/hppa/dl-trampoline.S: ... here.
* sysdeps/hppa/abort-instr.h: Use iitlbp with sr0.
* sysdeps/hppa/dl-lookupcfg.h: Inlcude dl-fptr.h.
(DL_FIXUP_VALUE_TYPE, DL_FIXUP_MAKE_VALUE, DL_FIXUP_VALUE_CODE_ADDR,
DL_FIXUP_VALUE_ADD, DL_FIXUP_ADDR_VALUE): Define.
* sysdeps/hppa/sysdep.h: Use "!" as a separator. Cleanup comments.
* sysdeps/hppa/bits/link.h (La_hppa_regs, La_hppa_retval): Define.
Define prototypes for la_hppa_gnu_pltenter and la_hppa_gnu_pltexit.
2006-05-14 23:54:47 +00:00
|
|
|
struct fdesc value)
|
2000-10-15 03:20:01 +00:00
|
|
|
{
|
2006-05-15 Carlos O'Donell <carlos@systemhalted.org>
* sysdeps/hppa/dl-machine.h: Include tls.h
(elf_machine_fixup_plt): Returns fdesc.
(elf_machine_profile_fixup_plt): Remove.
(elf_machine_plt_value): Returns fdesc.
(elf_machine_runtime_setup): Check that dl_profile != NULL.
(ARCH_LA_PLTENT, ARCH_LA_PLTEXIT): Define.
(RTLD_START): Use iitlbp with sr0.
(elf_machine_type_class): Include TLS relocs.
(reassemble_21, reassemble_14): Define.
(elf_machine_rela): Add DIR21L, DIR14R, PLABEL21L, PLABEL14R,
TLS_DTPMOD32, TLS_TPREL32, TLS_DTPOFF32 support.
(TRAMPOLINE_TEMPLATE): Move to ...
* sysdeps/hppa/dl-trampoline.S: ... here.
* sysdeps/hppa/abort-instr.h: Use iitlbp with sr0.
* sysdeps/hppa/dl-lookupcfg.h: Inlcude dl-fptr.h.
(DL_FIXUP_VALUE_TYPE, DL_FIXUP_MAKE_VALUE, DL_FIXUP_VALUE_CODE_ADDR,
DL_FIXUP_VALUE_ADD, DL_FIXUP_ADDR_VALUE): Define.
* sysdeps/hppa/sysdep.h: Use "!" as a separator. Cleanup comments.
* sysdeps/hppa/bits/link.h (La_hppa_regs, La_hppa_retval): Define.
Define prototypes for la_hppa_gnu_pltenter and la_hppa_gnu_pltexit.
2006-05-14 23:54:47 +00:00
|
|
|
/* We are rela only, return a function descriptor as a plt entry. */
|
|
|
|
return (struct fdesc) { value.ip + reloc->r_addend, value.gp };
|
2000-10-15 03:20:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set up the loaded object described by L so its unrelocated PLT
|
|
|
|
entries will jump to the on-demand fixup code in dl-runtime.c. */
|
|
|
|
|
|
|
|
static inline int
|
elf: Avoid nested functions in the loader [BZ #27220]
dynamic-link.h is included more than once in some elf/ files (rtld.c,
dl-conflict.c, dl-reloc.c, dl-reloc-static-pie.c) and uses GCC nested
functions. This harms readability and the nested functions usage
is the biggest obstacle prevents Clang build (Clang doesn't support GCC
nested functions).
The key idea for unnesting is to add extra parameters (struct link_map
*and struct r_scope_elm *[]) to RESOLVE_MAP,
ELF_MACHINE_BEFORE_RTLD_RELOC, ELF_DYNAMIC_RELOCATE, elf_machine_rel[a],
elf_machine_lazy_rel, and elf_machine_runtime_setup. (This is inspired
by Stan Shebs' ppc64/x86-64 implementation in the
google/grte/v5-2.27/master which uses mixed extra parameters and static
variables.)
Future simplification:
* If mips elf_machine_runtime_setup no longer needs RESOLVE_GOTSYM,
elf_machine_runtime_setup can drop the `scope` parameter.
* If TLSDESC no longer need to be in elf_machine_lazy_rel,
elf_machine_lazy_rel can drop the `scope` parameter.
Tested on aarch64, i386, x86-64, powerpc64le, powerpc64, powerpc32,
sparc64, sparcv9, s390x, s390, hppa, ia64, armhf, alpha, and mips64.
In addition, tested build-many-glibcs.py with {arc,csky,microblaze,nios2}-linux-gnu
and riscv64-linux-gnu-rv64imafdc-lp64d.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-10-07 18:55:02 +00:00
|
|
|
elf_machine_runtime_setup (struct link_map *l, struct r_scope_elem *scope[],
|
|
|
|
int lazy, int profile)
|
2000-10-15 03:20:01 +00:00
|
|
|
{
|
2004-04-17 22:53:29 +00:00
|
|
|
Elf32_Addr *got = NULL;
|
|
|
|
Elf32_Addr l_addr, iplt, jmprel, end_jmprel, r_type, r_sym;
|
|
|
|
const Elf32_Rela *reloc;
|
|
|
|
struct fdesc *fptr;
|
|
|
|
static union {
|
|
|
|
unsigned char c[8];
|
|
|
|
Elf32_Addr i[2];
|
|
|
|
} sig = {{0x00,0xc0,0xff,0xee, 0xde,0xad,0xbe,0xef}};
|
2011-10-05 09:52:45 +00:00
|
|
|
|
2022-02-14 15:14:49 +00:00
|
|
|
/* Initialize dp register for main executable. */
|
|
|
|
if (l->l_main_map)
|
|
|
|
{
|
|
|
|
register Elf32_Addr dp asm ("%r27");
|
|
|
|
|
|
|
|
dp = D_PTR (l, l_info[DT_PLTGOT]);
|
|
|
|
asm volatile ("" : : "r" (dp));
|
|
|
|
}
|
|
|
|
|
2004-04-17 22:53:29 +00:00
|
|
|
/* If we don't have a PLT we can just skip all this... */
|
|
|
|
if (__builtin_expect (l->l_info[DT_JMPREL] == NULL,0))
|
|
|
|
return lazy;
|
2011-10-05 09:52:45 +00:00
|
|
|
|
|
|
|
/* All paths use these values */
|
2004-04-17 22:53:29 +00:00
|
|
|
l_addr = l->l_addr;
|
|
|
|
jmprel = D_PTR(l, l_info[DT_JMPREL]);
|
|
|
|
end_jmprel = jmprel + l->l_info[DT_PLTRELSZ]->d_un.d_val;
|
2011-10-05 09:52:45 +00:00
|
|
|
|
2000-10-15 03:20:01 +00:00
|
|
|
extern void _dl_runtime_resolve (void);
|
|
|
|
extern void _dl_runtime_profile (void);
|
2011-10-05 09:52:45 +00:00
|
|
|
|
2004-04-17 22:53:29 +00:00
|
|
|
/* Linking lazily */
|
|
|
|
if (lazy)
|
2000-10-15 03:20:01 +00:00
|
|
|
{
|
2004-04-17 22:53:29 +00:00
|
|
|
/* FIXME: Search for the got, but backwards through the relocs, technically we should
|
2011-10-05 09:52:45 +00:00
|
|
|
find it on the first try. However, assuming the relocs got out of order the
|
|
|
|
routine is made a bit more robust by searching them all in case of failure. */
|
2019-02-27 13:55:45 +00:00
|
|
|
for (iplt = (end_jmprel - sizeof (Elf32_Rela)); iplt >= jmprel; iplt -= sizeof (Elf32_Rela))
|
2011-10-05 09:52:45 +00:00
|
|
|
{
|
|
|
|
|
2004-04-17 22:53:29 +00:00
|
|
|
reloc = (const Elf32_Rela *) iplt;
|
2011-10-05 09:52:45 +00:00
|
|
|
r_type = ELF32_R_TYPE (reloc->r_info);
|
|
|
|
r_sym = ELF32_R_SYM (reloc->r_info);
|
2004-04-17 22:53:29 +00:00
|
|
|
|
2011-10-05 09:52:45 +00:00
|
|
|
got = (Elf32_Addr *) (reloc->r_offset + l_addr + PLT_ENTRY_SIZE + SIZEOF_PLT_STUB);
|
2004-04-17 22:53:29 +00:00
|
|
|
|
2011-10-05 09:52:45 +00:00
|
|
|
/* If we aren't an IPLT, and we aren't NONE then it's a bad reloc */
|
|
|
|
if (__builtin_expect (r_type != R_PARISC_IPLT, 0))
|
2004-04-17 22:53:29 +00:00
|
|
|
{
|
|
|
|
if (__builtin_expect (r_type != R_PARISC_NONE, 0))
|
2011-10-05 09:52:45 +00:00
|
|
|
_dl_reloc_bad_type (l, r_type, 1);
|
2004-04-17 22:53:29 +00:00
|
|
|
continue;
|
|
|
|
}
|
2011-10-05 09:52:45 +00:00
|
|
|
|
|
|
|
/* Check for the plt_stub that binutils placed here for us
|
|
|
|
to use with _dl_runtime_resolve */
|
|
|
|
if (got[-2] != sig.i[0] || got[-1] != sig.i[1])
|
|
|
|
{
|
|
|
|
got = NULL; /* Not the stub... keep looking */
|
|
|
|
}
|
|
|
|
else
|
2004-04-17 22:53:29 +00:00
|
|
|
{
|
2011-10-05 09:52:45 +00:00
|
|
|
/* Found the GOT! */
|
|
|
|
register Elf32_Addr ltp __asm__ ("%r19");
|
|
|
|
|
|
|
|
/* Identify this shared object. Second entry in the got. */
|
|
|
|
got[1] = (Elf32_Addr) l;
|
|
|
|
|
|
|
|
/* This function will be called to perform the relocation. */
|
|
|
|
if (__builtin_expect (!profile, 1))
|
|
|
|
{
|
|
|
|
/* If a static application called us, then _dl_runtime_resolve is not
|
2004-04-17 22:53:29 +00:00
|
|
|
a function descriptor, but the *real* address of the function... */
|
|
|
|
if((unsigned long) &_dl_runtime_resolve & 3)
|
|
|
|
{
|
2011-10-05 09:52:45 +00:00
|
|
|
got[-2] = (Elf32_Addr) ((struct fdesc *)
|
|
|
|
((unsigned long) &_dl_runtime_resolve & ~3))->ip;
|
2004-04-17 22:53:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Static executable! */
|
2011-10-05 09:52:45 +00:00
|
|
|
got[-2] = (Elf32_Addr) &_dl_runtime_resolve;
|
2004-04-17 22:53:29 +00:00
|
|
|
}
|
2011-10-05 09:52:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (GLRO(dl_profile) != NULL
|
2006-05-15 Carlos O'Donell <carlos@systemhalted.org>
* sysdeps/hppa/dl-machine.h: Include tls.h
(elf_machine_fixup_plt): Returns fdesc.
(elf_machine_profile_fixup_plt): Remove.
(elf_machine_plt_value): Returns fdesc.
(elf_machine_runtime_setup): Check that dl_profile != NULL.
(ARCH_LA_PLTENT, ARCH_LA_PLTEXIT): Define.
(RTLD_START): Use iitlbp with sr0.
(elf_machine_type_class): Include TLS relocs.
(reassemble_21, reassemble_14): Define.
(elf_machine_rela): Add DIR21L, DIR14R, PLABEL21L, PLABEL14R,
TLS_DTPMOD32, TLS_TPREL32, TLS_DTPOFF32 support.
(TRAMPOLINE_TEMPLATE): Move to ...
* sysdeps/hppa/dl-trampoline.S: ... here.
* sysdeps/hppa/abort-instr.h: Use iitlbp with sr0.
* sysdeps/hppa/dl-lookupcfg.h: Inlcude dl-fptr.h.
(DL_FIXUP_VALUE_TYPE, DL_FIXUP_MAKE_VALUE, DL_FIXUP_VALUE_CODE_ADDR,
DL_FIXUP_VALUE_ADD, DL_FIXUP_ADDR_VALUE): Define.
* sysdeps/hppa/sysdep.h: Use "!" as a separator. Cleanup comments.
* sysdeps/hppa/bits/link.h (La_hppa_regs, La_hppa_retval): Define.
Define prototypes for la_hppa_gnu_pltenter and la_hppa_gnu_pltexit.
2006-05-14 23:54:47 +00:00
|
|
|
&& _dl_name_match_p (GLRO(dl_profile), l))
|
2011-10-05 09:52:45 +00:00
|
|
|
{
|
2004-04-17 22:53:29 +00:00
|
|
|
/* This is the object we are looking for. Say that
|
2011-10-05 09:52:45 +00:00
|
|
|
we really want profiling and the timers are
|
|
|
|
started. */
|
|
|
|
GL(dl_profile_map) = l;
|
|
|
|
}
|
2004-04-17 22:53:29 +00:00
|
|
|
|
2009-02-22 17:02:14 +00:00
|
|
|
if((unsigned long) &_dl_runtime_profile & 3)
|
2004-04-17 22:53:29 +00:00
|
|
|
{
|
2011-10-05 09:52:45 +00:00
|
|
|
got[-2] = (Elf32_Addr) ((struct fdesc *)
|
|
|
|
((unsigned long) &_dl_runtime_profile & ~3))->ip;
|
2004-04-17 22:53:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Static executable */
|
2011-10-05 09:52:45 +00:00
|
|
|
got[-2] = (Elf32_Addr) &_dl_runtime_profile;
|
2004-04-17 22:53:29 +00:00
|
|
|
}
|
2011-10-05 09:52:45 +00:00
|
|
|
}
|
|
|
|
/* Plunk in the gp of this function descriptor so we
|
|
|
|
can make the call to _dl_runtime_xxxxxx */
|
|
|
|
got[-1] = ltp;
|
|
|
|
break;
|
|
|
|
/* Done looking for the GOT, and stub is setup */
|
|
|
|
} /* else we found the GOT */
|
|
|
|
} /* for, walk the relocs backwards */
|
|
|
|
|
|
|
|
if(!got)
|
|
|
|
return 0; /* No lazy linking for you! */
|
|
|
|
|
|
|
|
/* Process all the relocs, now that we know the GOT... */
|
2000-10-15 03:20:01 +00:00
|
|
|
for (iplt = jmprel; iplt < end_jmprel; iplt += sizeof (Elf32_Rela))
|
|
|
|
{
|
|
|
|
reloc = (const Elf32_Rela *) iplt;
|
|
|
|
r_type = ELF32_R_TYPE (reloc->r_info);
|
|
|
|
r_sym = ELF32_R_SYM (reloc->r_info);
|
|
|
|
|
|
|
|
if (__builtin_expect (r_type == R_PARISC_IPLT, 1))
|
|
|
|
{
|
2004-04-17 22:53:29 +00:00
|
|
|
fptr = (struct fdesc *) (reloc->r_offset + l_addr);
|
2000-10-15 03:20:01 +00:00
|
|
|
if (r_sym != 0)
|
|
|
|
{
|
|
|
|
/* Relocate the pointer to the stub. */
|
2004-04-17 22:53:29 +00:00
|
|
|
fptr->ip = (Elf32_Addr) got - GOT_FROM_PLT_STUB;
|
|
|
|
|
2000-10-15 03:20:01 +00:00
|
|
|
/* Instead of the LTP value, we put the reloc offset
|
|
|
|
here. The trampoline code will load the proper
|
|
|
|
LTP and pass the reloc offset to the fixup
|
|
|
|
function. */
|
Fix data race in setting function descriptors during lazy binding on hppa.
This addresses an issue that is present mainly on SMP machines running
threaded code. In a typical indirect call or PLT import stub, the
target address is loaded first. Then the global pointer is loaded into
the PIC register in the delay slot of a branch to the target address.
During lazy binding, the target address is a trampoline which transfers
to _dl_runtime_resolve().
_dl_runtime_resolve() uses the relocation offset stored in the global
pointer and the linkage map stored in the trampoline to find the
relocation. Then, the function descriptor is updated.
In a multi-threaded application, it is possible for the global pointer
to be updated between the load of the target address and the global
pointer. When this happens, the relocation offset has been replaced
by the new global pointer. The function pointer has probably been
updated as well but there is no way to find the address of the function
descriptor and to transfer to the target. So, _dl_runtime_resolve()
typically crashes.
HP-UX addressed this problem by adding an extra pc-relative branch to
the trampoline. The descriptor is initially setup to point to the
branch. The branch then transfers to the trampoline. This allowed
the trampoline code to figure out which descriptor was being used
without any modification to user code. I didn't use this approach
as it is more complex and changes function pointer canonicalization.
The order of loading the target address and global pointer in
indirect calls was not consistent with the order used in import stubs.
In particular, $$dyncall and some inline versions of it loaded the
global pointer first. This was inconsistent with the global pointer
being updated first in dl-machine.h. Assuming the accesses are
ordered, we want elf_machine_fixup_plt() to store the global pointer
first and calls to load it last. Then, the global pointer will be
correct when the target function is entered.
However, just to make things more fun, HP added support for
out-of-order execution of accesses in PA 2.0. The accesses used by
calls are weakly ordered. So, it's possibly under some circumstances
that a function might be entered with the wrong global pointer.
However, HP uses weakly ordered accesses in 64-bit HP-UX, so I assume
that loading the global pointer in the delay slot of the branch must
work consistently.
The basic fix for the race is a combination of modifying user code to
preserve the address of the function descriptor in register %r22 and
setting the least-significant bit in the relocation offset. The
latter was suggested by Carlos as a way to distinguish relocation
offsets from global pointer values. Conventionally, %r22 is used
as the address of the function descriptor in calls to $$dyncall.
So, it wasn't hard to preserve the address in %r22.
I have updated gcc trunk and gcc-9 branch to not clobber %r22 in
$$dyncall and inline indirect calls. I have also modified the import
stubs in binutils trunk and the 2.33 branch to preserve %r22. This
required making the stubs one instruction longer but we save one
relocation. I also modified binutils to align the .plt section on
a 8-byte boundary. This allows descriptors to be updated atomically
with a floting-point store.
With these changes, _dl_runtime_resolve() can fallback to an alternate
mechanism to find the relocation offset when it has been clobbered.
There's just one additional instruction in the fast path. I tested
the fallback function, _dl_fix_reloc_arg(), by changing the branch to
always use the fallback. Old code still runs as it did before.
Fixes bug 23296.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2020-03-30 20:36:49 +00:00
|
|
|
fptr->gp = (iplt - jmprel) | PA_GP_RELOC;
|
2004-04-17 22:53:29 +00:00
|
|
|
} /* r_sym != 0 */
|
2000-10-15 03:20:01 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Relocate this *ABS* entry. */
|
2004-04-17 22:53:29 +00:00
|
|
|
fptr->ip = reloc->r_addend + l_addr;
|
2000-10-15 03:20:01 +00:00
|
|
|
fptr->gp = D_PTR (l, l_info[DT_PLTGOT]);
|
|
|
|
}
|
2004-04-17 22:53:29 +00:00
|
|
|
} /* r_type == R_PARISC_IPLT */
|
2011-10-05 09:52:45 +00:00
|
|
|
} /* for all the relocations */
|
2004-04-17 22:53:29 +00:00
|
|
|
} /* if lazy */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (iplt = jmprel; iplt < end_jmprel; iplt += sizeof (Elf32_Rela))
|
2011-10-05 09:52:45 +00:00
|
|
|
{
|
|
|
|
reloc = (const Elf32_Rela *) iplt;
|
|
|
|
r_type = ELF32_R_TYPE (reloc->r_info);
|
|
|
|
r_sym = ELF32_R_SYM (reloc->r_info);
|
|
|
|
|
|
|
|
if (__builtin_expect ((r_type == R_PARISC_IPLT) && (r_sym == 0), 1))
|
|
|
|
{
|
|
|
|
fptr = (struct fdesc *) (reloc->r_offset + l_addr);
|
|
|
|
/* Relocate this *ABS* entry, set only the gp, the rest is set later
|
|
|
|
when elf_machine_rela_relative is called (WITHOUT the linkmap) */
|
|
|
|
fptr->gp = D_PTR (l, l_info[DT_PLTGOT]);
|
|
|
|
} /* r_type == R_PARISC_IPLT */
|
|
|
|
} /* for all the relocations */
|
|
|
|
}
|
2000-10-15 03:20:01 +00:00
|
|
|
return lazy;
|
|
|
|
}
|
|
|
|
|
2006-05-15 Carlos O'Donell <carlos@systemhalted.org>
* sysdeps/hppa/dl-machine.h: Include tls.h
(elf_machine_fixup_plt): Returns fdesc.
(elf_machine_profile_fixup_plt): Remove.
(elf_machine_plt_value): Returns fdesc.
(elf_machine_runtime_setup): Check that dl_profile != NULL.
(ARCH_LA_PLTENT, ARCH_LA_PLTEXIT): Define.
(RTLD_START): Use iitlbp with sr0.
(elf_machine_type_class): Include TLS relocs.
(reassemble_21, reassemble_14): Define.
(elf_machine_rela): Add DIR21L, DIR14R, PLABEL21L, PLABEL14R,
TLS_DTPMOD32, TLS_TPREL32, TLS_DTPOFF32 support.
(TRAMPOLINE_TEMPLATE): Move to ...
* sysdeps/hppa/dl-trampoline.S: ... here.
* sysdeps/hppa/abort-instr.h: Use iitlbp with sr0.
* sysdeps/hppa/dl-lookupcfg.h: Inlcude dl-fptr.h.
(DL_FIXUP_VALUE_TYPE, DL_FIXUP_MAKE_VALUE, DL_FIXUP_VALUE_CODE_ADDR,
DL_FIXUP_VALUE_ADD, DL_FIXUP_ADDR_VALUE): Define.
* sysdeps/hppa/sysdep.h: Use "!" as a separator. Cleanup comments.
* sysdeps/hppa/bits/link.h (La_hppa_regs, La_hppa_retval): Define.
Define prototypes for la_hppa_gnu_pltenter and la_hppa_gnu_pltexit.
2006-05-14 23:54:47 +00:00
|
|
|
|
|
|
|
/* Names of the architecture-specific auditing callback functions. */
|
|
|
|
#define ARCH_LA_PLTENTER hppa_gnu_pltenter
|
|
|
|
#define ARCH_LA_PLTEXIT hppa_gnu_pltexit
|
|
|
|
|
2017-02-21 01:31:57 +00:00
|
|
|
/* Adjust DL_STACK_END to get value we want in __libc_stack_end. */
|
|
|
|
#define DL_STACK_END(cookie) \
|
|
|
|
((void *) (((long) (cookie)) + 0x160))
|
|
|
|
|
2000-10-15 03:20:01 +00:00
|
|
|
/* Initial entry point code for the dynamic linker.
|
|
|
|
The C function `_dl_start' is the real entry point;
|
|
|
|
its return value is the user program's entry point. */
|
|
|
|
|
2001-04-24 19:38:55 +00:00
|
|
|
#define RTLD_START \
|
2022-10-01 19:49:25 +00:00
|
|
|
/* Set up dp for any non-PIC lib constructors that may be called. */ \
|
|
|
|
static struct link_map * __attribute__((used)) \
|
|
|
|
set_dp (struct link_map *map) \
|
|
|
|
{ \
|
|
|
|
register Elf32_Addr dp asm ("%r27"); \
|
|
|
|
dp = D_PTR (map, l_info[DT_PLTGOT]); \
|
|
|
|
asm volatile ("" : : "r" (dp)); \
|
|
|
|
return map; \
|
|
|
|
} \
|
|
|
|
\
|
2001-06-06 11:52:59 +00:00
|
|
|
asm ( \
|
|
|
|
" .text\n" \
|
|
|
|
" .globl _start\n" \
|
|
|
|
" .type _start,@function\n" \
|
|
|
|
"_start:\n" \
|
|
|
|
/* The kernel does not give us an initial stack frame. */ \
|
|
|
|
" ldo 64(%sp),%sp\n" \
|
|
|
|
\
|
2004-04-17 22:53:29 +00:00
|
|
|
/* We need the LTP, and we need it now. \
|
|
|
|
$PIC_pcrel$0 points 8 bytes past the current instruction, \
|
|
|
|
just like a branch reloc. This sequence gets us the \
|
|
|
|
runtime address of _DYNAMIC. */ \
|
2001-06-06 11:52:59 +00:00
|
|
|
" bl 0f,%r19\n" \
|
2017-12-02 16:04:16 +00:00
|
|
|
" addil L'_DYNAMIC - ($PIC_pcrel$0 - 1),%r19\n" \
|
|
|
|
"0: ldo R'_DYNAMIC - ($PIC_pcrel$0 - 5)(%r1),%r26\n" \
|
2001-06-06 11:52:59 +00:00
|
|
|
\
|
2004-04-17 22:53:29 +00:00
|
|
|
/* The link time address is stored in the first entry of the \
|
|
|
|
GOT. */ \
|
2017-12-02 16:04:16 +00:00
|
|
|
" addil L'_GLOBAL_OFFSET_TABLE_ - ($PIC_pcrel$0 - 9),%r19\n" \
|
|
|
|
" ldw R'_GLOBAL_OFFSET_TABLE_ - ($PIC_pcrel$0 - 13)(%r1),%r20\n" \
|
2001-06-06 11:52:59 +00:00
|
|
|
\
|
|
|
|
" sub %r26,%r20,%r20\n" /* Calculate load offset */ \
|
|
|
|
\
|
2004-04-17 22:53:29 +00:00
|
|
|
/* Rummage through the dynamic entries, looking for \
|
|
|
|
DT_PLTGOT. */ \
|
2001-06-06 11:52:59 +00:00
|
|
|
" ldw,ma 8(%r26),%r19\n" \
|
|
|
|
"1: cmpib,=,n 3,%r19,2f\n" /* tag == DT_PLTGOT? */ \
|
|
|
|
" cmpib,<>,n 0,%r19,1b\n" \
|
|
|
|
" ldw,ma 8(%r26),%r19\n" \
|
|
|
|
\
|
|
|
|
/* Uh oh! We didn't find one. Abort. */ \
|
2006-05-15 Carlos O'Donell <carlos@systemhalted.org>
* sysdeps/hppa/dl-machine.h: Include tls.h
(elf_machine_fixup_plt): Returns fdesc.
(elf_machine_profile_fixup_plt): Remove.
(elf_machine_plt_value): Returns fdesc.
(elf_machine_runtime_setup): Check that dl_profile != NULL.
(ARCH_LA_PLTENT, ARCH_LA_PLTEXIT): Define.
(RTLD_START): Use iitlbp with sr0.
(elf_machine_type_class): Include TLS relocs.
(reassemble_21, reassemble_14): Define.
(elf_machine_rela): Add DIR21L, DIR14R, PLABEL21L, PLABEL14R,
TLS_DTPMOD32, TLS_TPREL32, TLS_DTPOFF32 support.
(TRAMPOLINE_TEMPLATE): Move to ...
* sysdeps/hppa/dl-trampoline.S: ... here.
* sysdeps/hppa/abort-instr.h: Use iitlbp with sr0.
* sysdeps/hppa/dl-lookupcfg.h: Inlcude dl-fptr.h.
(DL_FIXUP_VALUE_TYPE, DL_FIXUP_MAKE_VALUE, DL_FIXUP_VALUE_CODE_ADDR,
DL_FIXUP_VALUE_ADD, DL_FIXUP_ADDR_VALUE): Define.
* sysdeps/hppa/sysdep.h: Use "!" as a separator. Cleanup comments.
* sysdeps/hppa/bits/link.h (La_hppa_regs, La_hppa_retval): Define.
Define prototypes for la_hppa_gnu_pltenter and la_hppa_gnu_pltexit.
2006-05-14 23:54:47 +00:00
|
|
|
" iitlbp %r0,(%sr0,%r0)\n" \
|
2001-06-06 11:52:59 +00:00
|
|
|
\
|
|
|
|
"2: ldw -4(%r26),%r19\n" /* Found it, load value. */ \
|
|
|
|
" add %r19,%r20,%r19\n" /* And add the load offset. */ \
|
|
|
|
\
|
|
|
|
/* Our initial stack layout is rather different from everyone \
|
|
|
|
else's due to the unique PA-RISC ABI. As far as I know it \
|
|
|
|
looks like this: \
|
|
|
|
\
|
|
|
|
----------------------------------- (this frame created above) \
|
|
|
|
| 32 bytes of magic | \
|
|
|
|
|---------------------------------| \
|
|
|
|
| 32 bytes argument/sp save area | \
|
2004-04-17 22:53:29 +00:00
|
|
|
|---------------------------------| ((current->mm->env_end) \
|
|
|
|
| N bytes of slack | + 63 & ~63) \
|
2001-06-06 11:52:59 +00:00
|
|
|
|---------------------------------| \
|
|
|
|
| envvar and arg strings | \
|
|
|
|
|---------------------------------| \
|
|
|
|
| ELF auxiliary info | \
|
|
|
|
| (up to 28 words) | \
|
|
|
|
|---------------------------------| \
|
|
|
|
| Environment variable pointers | \
|
|
|
|
| upwards to NULL | \
|
|
|
|
|---------------------------------| \
|
|
|
|
| Argument pointers | \
|
|
|
|
| upwards to NULL | \
|
|
|
|
|---------------------------------| \
|
|
|
|
| argc (1 word) | \
|
|
|
|
----------------------------------- \
|
|
|
|
\
|
|
|
|
So, obviously, we can't just pass %sp to _dl_start. That's \
|
|
|
|
okay, argv-4 will do just fine. \
|
|
|
|
\
|
2022-05-25 11:58:38 +00:00
|
|
|
This is always within range so we'll be okay. */ \
|
2001-06-06 11:52:59 +00:00
|
|
|
" bl _dl_start,%rp\n" \
|
|
|
|
" ldo -4(%r24),%r26\n" \
|
|
|
|
\
|
|
|
|
" .globl _dl_start_user\n" \
|
|
|
|
" .type _dl_start_user,@function\n" \
|
|
|
|
"_dl_start_user:\n" \
|
|
|
|
/* Save the entry point in %r3. */ \
|
|
|
|
" copy %ret0,%r3\n" \
|
|
|
|
\
|
2022-05-25 11:58:38 +00:00
|
|
|
/* The loader adjusts argc, argv, env, and the aux vectors \
|
|
|
|
directly on the stack to remove any arguments used for \
|
|
|
|
direct loader invocation. Thus, argc and argv must be \
|
|
|
|
reloaded from from _dl_argc and _dl_argv. */ \
|
2001-06-06 11:52:59 +00:00
|
|
|
\
|
2022-10-01 19:49:25 +00:00
|
|
|
/* Load main_map from _rtld_local and setup dp. */ \
|
|
|
|
" addil LT'_rtld_local,%r19\n" \
|
|
|
|
" ldw RT'_rtld_local(%r1),%r26\n" \
|
|
|
|
" bl set_dp, %r2\n" \
|
|
|
|
" ldw 0(%r26),%r26\n" \
|
|
|
|
" copy %ret0,%r26\n" \
|
|
|
|
\
|
2022-05-25 11:58:38 +00:00
|
|
|
/* Load argc from _dl_argc. */ \
|
|
|
|
" addil LT'_dl_argc,%r19\n" \
|
|
|
|
" ldw RT'_dl_argc(%r1),%r20\n" \
|
|
|
|
" ldw 0(%r20),%r25\n" \
|
2001-06-06 11:52:59 +00:00
|
|
|
" stw %r25,-40(%sp)\n" \
|
2022-05-25 11:58:38 +00:00
|
|
|
\
|
|
|
|
/* Same for argv with _dl_argv. */ \
|
|
|
|
" addil LT'_dl_argv,%r19\n" \
|
|
|
|
" ldw RT'_dl_argv(%r1),%r20\n" \
|
|
|
|
" ldw 0(%r20),%r24\n" \
|
2001-06-06 11:52:59 +00:00
|
|
|
" stw %r24,-44(%sp)\n" \
|
|
|
|
\
|
|
|
|
/* envp = argv + argc + 1 */ \
|
|
|
|
" sh2add %r25,%r24,%r23\n" \
|
2022-10-01 19:49:25 +00:00
|
|
|
\
|
|
|
|
/* Call _dl_init(main_map, argc, argv, envp). */ \
|
2014-11-04 23:26:39 +00:00
|
|
|
" bl _dl_init,%r2\n" \
|
2001-06-06 11:52:59 +00:00
|
|
|
" ldo 4(%r23),%r23\n" /* delay slot */ \
|
|
|
|
\
|
2004-04-17 22:53:29 +00:00
|
|
|
/* Reload argc, argv to the registers start.S expects. */ \
|
2001-06-06 11:52:59 +00:00
|
|
|
" ldw -40(%sp),%r25\n" \
|
|
|
|
" ldw -44(%sp),%r24\n" \
|
|
|
|
\
|
2006-09-13 21:56:09 +00:00
|
|
|
/* _dl_fini is a local function in the loader, so we construct \
|
2011-10-05 09:52:45 +00:00
|
|
|
a false OPD here and pass this to the application. */ \
|
2006-09-13 21:56:09 +00:00
|
|
|
/* FIXME: Should be able to use P%, and LR RR to have the \
|
|
|
|
the linker construct a proper OPD. */ \
|
2001-06-06 11:52:59 +00:00
|
|
|
" .section .data\n" \
|
|
|
|
"__dl_fini_plabel:\n" \
|
|
|
|
" .word _dl_fini\n" \
|
|
|
|
" .word 0xdeadbeef\n" \
|
|
|
|
" .previous\n" \
|
|
|
|
\
|
2004-04-17 22:53:29 +00:00
|
|
|
/* %r3 contains a function pointer, we need to mask out the \
|
|
|
|
lower bits and load the gp and jump address. */ \
|
2001-06-06 11:52:59 +00:00
|
|
|
" depi 0,31,2,%r3\n" \
|
|
|
|
" ldw 0(%r3),%r2\n" \
|
|
|
|
" addil LT'__dl_fini_plabel,%r19\n" \
|
|
|
|
" ldw RT'__dl_fini_plabel(%r1),%r23\n" \
|
|
|
|
" stw %r19,4(%r23)\n" \
|
|
|
|
" ldw 4(%r3),%r19\n" /* load the object's gp */ \
|
|
|
|
" bv %r0(%r2)\n" \
|
|
|
|
" depi 2,31,2,%r23\n" /* delay slot */ \
|
2006-05-15 Carlos O'Donell <carlos@systemhalted.org>
* sysdeps/hppa/dl-machine.h: Include tls.h
(elf_machine_fixup_plt): Returns fdesc.
(elf_machine_profile_fixup_plt): Remove.
(elf_machine_plt_value): Returns fdesc.
(elf_machine_runtime_setup): Check that dl_profile != NULL.
(ARCH_LA_PLTENT, ARCH_LA_PLTEXIT): Define.
(RTLD_START): Use iitlbp with sr0.
(elf_machine_type_class): Include TLS relocs.
(reassemble_21, reassemble_14): Define.
(elf_machine_rela): Add DIR21L, DIR14R, PLABEL21L, PLABEL14R,
TLS_DTPMOD32, TLS_TPREL32, TLS_DTPOFF32 support.
(TRAMPOLINE_TEMPLATE): Move to ...
* sysdeps/hppa/dl-trampoline.S: ... here.
* sysdeps/hppa/abort-instr.h: Use iitlbp with sr0.
* sysdeps/hppa/dl-lookupcfg.h: Inlcude dl-fptr.h.
(DL_FIXUP_VALUE_TYPE, DL_FIXUP_MAKE_VALUE, DL_FIXUP_VALUE_CODE_ADDR,
DL_FIXUP_VALUE_ADD, DL_FIXUP_ADDR_VALUE): Define.
* sysdeps/hppa/sysdep.h: Use "!" as a separator. Cleanup comments.
* sysdeps/hppa/bits/link.h (La_hppa_regs, La_hppa_retval): Define.
Define prototypes for la_hppa_gnu_pltenter and la_hppa_gnu_pltexit.
2006-05-14 23:54:47 +00:00
|
|
|
);
|
2000-10-15 03:20:01 +00:00
|
|
|
|
2011-10-05 09:52:45 +00:00
|
|
|
/* ELF_RTYPE_CLASS_PLT iff TYPE describes relocation of a PLT entry or
|
2006-05-15 Carlos O'Donell <carlos@systemhalted.org>
* sysdeps/hppa/dl-machine.h: Include tls.h
(elf_machine_fixup_plt): Returns fdesc.
(elf_machine_profile_fixup_plt): Remove.
(elf_machine_plt_value): Returns fdesc.
(elf_machine_runtime_setup): Check that dl_profile != NULL.
(ARCH_LA_PLTENT, ARCH_LA_PLTEXIT): Define.
(RTLD_START): Use iitlbp with sr0.
(elf_machine_type_class): Include TLS relocs.
(reassemble_21, reassemble_14): Define.
(elf_machine_rela): Add DIR21L, DIR14R, PLABEL21L, PLABEL14R,
TLS_DTPMOD32, TLS_TPREL32, TLS_DTPOFF32 support.
(TRAMPOLINE_TEMPLATE): Move to ...
* sysdeps/hppa/dl-trampoline.S: ... here.
* sysdeps/hppa/abort-instr.h: Use iitlbp with sr0.
* sysdeps/hppa/dl-lookupcfg.h: Inlcude dl-fptr.h.
(DL_FIXUP_VALUE_TYPE, DL_FIXUP_MAKE_VALUE, DL_FIXUP_VALUE_CODE_ADDR,
DL_FIXUP_VALUE_ADD, DL_FIXUP_ADDR_VALUE): Define.
* sysdeps/hppa/sysdep.h: Use "!" as a separator. Cleanup comments.
* sysdeps/hppa/bits/link.h (La_hppa_regs, La_hppa_retval): Define.
Define prototypes for la_hppa_gnu_pltenter and la_hppa_gnu_pltexit.
2006-05-14 23:54:47 +00:00
|
|
|
a TLS variable, so references should not be allowed to define the value.
|
2015-03-05 16:26:21 +00:00
|
|
|
ELF_RTYPE_CLASS_COPY iff TYPE should not be allowed to resolve to one
|
2001-08-26 22:26:38 +00:00
|
|
|
of the main executable's symbols, as for a COPY reloc. */
|
2015-08-15 02:07:40 +00:00
|
|
|
#if !defined RTLD_BOOTSTRAP
|
2006-05-15 Carlos O'Donell <carlos@systemhalted.org>
* sysdeps/hppa/dl-machine.h: Include tls.h
(elf_machine_fixup_plt): Returns fdesc.
(elf_machine_profile_fixup_plt): Remove.
(elf_machine_plt_value): Returns fdesc.
(elf_machine_runtime_setup): Check that dl_profile != NULL.
(ARCH_LA_PLTENT, ARCH_LA_PLTEXIT): Define.
(RTLD_START): Use iitlbp with sr0.
(elf_machine_type_class): Include TLS relocs.
(reassemble_21, reassemble_14): Define.
(elf_machine_rela): Add DIR21L, DIR14R, PLABEL21L, PLABEL14R,
TLS_DTPMOD32, TLS_TPREL32, TLS_DTPOFF32 support.
(TRAMPOLINE_TEMPLATE): Move to ...
* sysdeps/hppa/dl-trampoline.S: ... here.
* sysdeps/hppa/abort-instr.h: Use iitlbp with sr0.
* sysdeps/hppa/dl-lookupcfg.h: Inlcude dl-fptr.h.
(DL_FIXUP_VALUE_TYPE, DL_FIXUP_MAKE_VALUE, DL_FIXUP_VALUE_CODE_ADDR,
DL_FIXUP_VALUE_ADD, DL_FIXUP_ADDR_VALUE): Define.
* sysdeps/hppa/sysdep.h: Use "!" as a separator. Cleanup comments.
* sysdeps/hppa/bits/link.h (La_hppa_regs, La_hppa_retval): Define.
Define prototypes for la_hppa_gnu_pltenter and la_hppa_gnu_pltexit.
2006-05-14 23:54:47 +00:00
|
|
|
# define elf_machine_type_class(type) \
|
2014-04-29 07:08:48 +00:00
|
|
|
((((type) == R_PARISC_IPLT \
|
2006-05-15 Carlos O'Donell <carlos@systemhalted.org>
* sysdeps/hppa/dl-machine.h: Include tls.h
(elf_machine_fixup_plt): Returns fdesc.
(elf_machine_profile_fixup_plt): Remove.
(elf_machine_plt_value): Returns fdesc.
(elf_machine_runtime_setup): Check that dl_profile != NULL.
(ARCH_LA_PLTENT, ARCH_LA_PLTEXIT): Define.
(RTLD_START): Use iitlbp with sr0.
(elf_machine_type_class): Include TLS relocs.
(reassemble_21, reassemble_14): Define.
(elf_machine_rela): Add DIR21L, DIR14R, PLABEL21L, PLABEL14R,
TLS_DTPMOD32, TLS_TPREL32, TLS_DTPOFF32 support.
(TRAMPOLINE_TEMPLATE): Move to ...
* sysdeps/hppa/dl-trampoline.S: ... here.
* sysdeps/hppa/abort-instr.h: Use iitlbp with sr0.
* sysdeps/hppa/dl-lookupcfg.h: Inlcude dl-fptr.h.
(DL_FIXUP_VALUE_TYPE, DL_FIXUP_MAKE_VALUE, DL_FIXUP_VALUE_CODE_ADDR,
DL_FIXUP_VALUE_ADD, DL_FIXUP_ADDR_VALUE): Define.
* sysdeps/hppa/sysdep.h: Use "!" as a separator. Cleanup comments.
* sysdeps/hppa/bits/link.h (La_hppa_regs, La_hppa_retval): Define.
Define prototypes for la_hppa_gnu_pltenter and la_hppa_gnu_pltexit.
2006-05-14 23:54:47 +00:00
|
|
|
|| (type) == R_PARISC_EPLT \
|
|
|
|
|| (type) == R_PARISC_TLS_DTPMOD32 \
|
|
|
|
|| (type) == R_PARISC_TLS_DTPOFF32 \
|
|
|
|
|| (type) == R_PARISC_TLS_TPREL32) \
|
|
|
|
* ELF_RTYPE_CLASS_PLT) \
|
|
|
|
| (((type) == R_PARISC_COPY) * ELF_RTYPE_CLASS_COPY))
|
|
|
|
#else
|
2014-04-29 07:08:48 +00:00
|
|
|
#define elf_machine_type_class(type) \
|
2006-05-15 Carlos O'Donell <carlos@systemhalted.org>
* sysdeps/hppa/dl-machine.h: Include tls.h
(elf_machine_fixup_plt): Returns fdesc.
(elf_machine_profile_fixup_plt): Remove.
(elf_machine_plt_value): Returns fdesc.
(elf_machine_runtime_setup): Check that dl_profile != NULL.
(ARCH_LA_PLTENT, ARCH_LA_PLTEXIT): Define.
(RTLD_START): Use iitlbp with sr0.
(elf_machine_type_class): Include TLS relocs.
(reassemble_21, reassemble_14): Define.
(elf_machine_rela): Add DIR21L, DIR14R, PLABEL21L, PLABEL14R,
TLS_DTPMOD32, TLS_TPREL32, TLS_DTPOFF32 support.
(TRAMPOLINE_TEMPLATE): Move to ...
* sysdeps/hppa/dl-trampoline.S: ... here.
* sysdeps/hppa/abort-instr.h: Use iitlbp with sr0.
* sysdeps/hppa/dl-lookupcfg.h: Inlcude dl-fptr.h.
(DL_FIXUP_VALUE_TYPE, DL_FIXUP_MAKE_VALUE, DL_FIXUP_VALUE_CODE_ADDR,
DL_FIXUP_VALUE_ADD, DL_FIXUP_ADDR_VALUE): Define.
* sysdeps/hppa/sysdep.h: Use "!" as a separator. Cleanup comments.
* sysdeps/hppa/bits/link.h (La_hppa_regs, La_hppa_retval): Define.
Define prototypes for la_hppa_gnu_pltenter and la_hppa_gnu_pltexit.
2006-05-14 23:54:47 +00:00
|
|
|
((((type) == R_PARISC_IPLT \
|
|
|
|
|| (type) == R_PARISC_EPLT) \
|
|
|
|
* ELF_RTYPE_CLASS_PLT) \
|
2001-08-26 22:26:38 +00:00
|
|
|
| (((type) == R_PARISC_COPY) * ELF_RTYPE_CLASS_COPY))
|
2006-05-15 Carlos O'Donell <carlos@systemhalted.org>
* sysdeps/hppa/dl-machine.h: Include tls.h
(elf_machine_fixup_plt): Returns fdesc.
(elf_machine_profile_fixup_plt): Remove.
(elf_machine_plt_value): Returns fdesc.
(elf_machine_runtime_setup): Check that dl_profile != NULL.
(ARCH_LA_PLTENT, ARCH_LA_PLTEXIT): Define.
(RTLD_START): Use iitlbp with sr0.
(elf_machine_type_class): Include TLS relocs.
(reassemble_21, reassemble_14): Define.
(elf_machine_rela): Add DIR21L, DIR14R, PLABEL21L, PLABEL14R,
TLS_DTPMOD32, TLS_TPREL32, TLS_DTPOFF32 support.
(TRAMPOLINE_TEMPLATE): Move to ...
* sysdeps/hppa/dl-trampoline.S: ... here.
* sysdeps/hppa/abort-instr.h: Use iitlbp with sr0.
* sysdeps/hppa/dl-lookupcfg.h: Inlcude dl-fptr.h.
(DL_FIXUP_VALUE_TYPE, DL_FIXUP_MAKE_VALUE, DL_FIXUP_VALUE_CODE_ADDR,
DL_FIXUP_VALUE_ADD, DL_FIXUP_ADDR_VALUE): Define.
* sysdeps/hppa/sysdep.h: Use "!" as a separator. Cleanup comments.
* sysdeps/hppa/bits/link.h (La_hppa_regs, La_hppa_retval): Define.
Define prototypes for la_hppa_gnu_pltenter and la_hppa_gnu_pltexit.
2006-05-14 23:54:47 +00:00
|
|
|
#endif
|
2000-10-15 03:20:01 +00:00
|
|
|
|
2004-04-17 22:53:29 +00:00
|
|
|
/* Used by the runtime in fixup to figure out if reloc is *really* PLT */
|
2000-10-15 03:20:01 +00:00
|
|
|
#define ELF_MACHINE_JMP_SLOT R_PARISC_IPLT
|
2004-04-17 22:53:29 +00:00
|
|
|
#define ELF_MACHINE_SIZEOF_JMP_SLOT PLT_ENTRY_SIZE
|
2000-10-15 03:20:01 +00:00
|
|
|
|
2001-04-22 03:22:03 +00:00
|
|
|
/* Return the address of the entry point. */
|
2013-11-21 18:23:16 +00:00
|
|
|
#define ELF_MACHINE_START_ADDRESS(map, start) \
|
|
|
|
({ \
|
|
|
|
ElfW(Addr) addr; \
|
|
|
|
DL_DT_FUNCTION_ADDRESS(map, start, static, addr) \
|
|
|
|
addr; \
|
|
|
|
})
|
2004-04-17 22:53:29 +00:00
|
|
|
|
|
|
|
/* We define an initialization functions. This is called very early in
|
|
|
|
* _dl_sysdep_start. */
|
|
|
|
#define DL_PLATFORM_INIT dl_platform_init ()
|
2001-04-22 03:22:03 +00:00
|
|
|
|
2004-04-17 22:53:29 +00:00
|
|
|
static inline void __attribute__ ((unused))
|
|
|
|
dl_platform_init (void)
|
|
|
|
{
|
|
|
|
if (GLRO(dl_platform) != NULL && *GLRO(dl_platform) == '\0')
|
|
|
|
/* Avoid an empty string which would disturb us. */
|
|
|
|
GLRO(dl_platform) = NULL;
|
|
|
|
}
|
2011-10-05 09:52:45 +00:00
|
|
|
|
2000-10-15 03:20:01 +00:00
|
|
|
#endif /* !dl_machine_h */
|
|
|
|
|
|
|
|
/* These are only actually used where RESOLVE_MAP is defined, anyway. */
|
|
|
|
#ifdef RESOLVE_MAP
|
|
|
|
|
2006-05-15 Carlos O'Donell <carlos@systemhalted.org>
* sysdeps/hppa/dl-machine.h: Include tls.h
(elf_machine_fixup_plt): Returns fdesc.
(elf_machine_profile_fixup_plt): Remove.
(elf_machine_plt_value): Returns fdesc.
(elf_machine_runtime_setup): Check that dl_profile != NULL.
(ARCH_LA_PLTENT, ARCH_LA_PLTEXIT): Define.
(RTLD_START): Use iitlbp with sr0.
(elf_machine_type_class): Include TLS relocs.
(reassemble_21, reassemble_14): Define.
(elf_machine_rela): Add DIR21L, DIR14R, PLABEL21L, PLABEL14R,
TLS_DTPMOD32, TLS_TPREL32, TLS_DTPOFF32 support.
(TRAMPOLINE_TEMPLATE): Move to ...
* sysdeps/hppa/dl-trampoline.S: ... here.
* sysdeps/hppa/abort-instr.h: Use iitlbp with sr0.
* sysdeps/hppa/dl-lookupcfg.h: Inlcude dl-fptr.h.
(DL_FIXUP_VALUE_TYPE, DL_FIXUP_MAKE_VALUE, DL_FIXUP_VALUE_CODE_ADDR,
DL_FIXUP_VALUE_ADD, DL_FIXUP_ADDR_VALUE): Define.
* sysdeps/hppa/sysdep.h: Use "!" as a separator. Cleanup comments.
* sysdeps/hppa/bits/link.h (La_hppa_regs, La_hppa_retval): Define.
Define prototypes for la_hppa_gnu_pltenter and la_hppa_gnu_pltexit.
2006-05-14 23:54:47 +00:00
|
|
|
#define reassemble_21(as21) \
|
|
|
|
( (((as21) & 0x100000) >> 20) \
|
|
|
|
| (((as21) & 0x0ffe00) >> 8) \
|
|
|
|
| (((as21) & 0x000180) << 7) \
|
|
|
|
| (((as21) & 0x00007c) << 14) \
|
|
|
|
| (((as21) & 0x000003) << 12))
|
|
|
|
|
|
|
|
#define reassemble_14(as14) \
|
|
|
|
( (((as14) & 0x1fff) << 1) \
|
|
|
|
| (((as14) & 0x2000) >> 13))
|
|
|
|
|
elf: Avoid nested functions in the loader [BZ #27220]
dynamic-link.h is included more than once in some elf/ files (rtld.c,
dl-conflict.c, dl-reloc.c, dl-reloc-static-pie.c) and uses GCC nested
functions. This harms readability and the nested functions usage
is the biggest obstacle prevents Clang build (Clang doesn't support GCC
nested functions).
The key idea for unnesting is to add extra parameters (struct link_map
*and struct r_scope_elm *[]) to RESOLVE_MAP,
ELF_MACHINE_BEFORE_RTLD_RELOC, ELF_DYNAMIC_RELOCATE, elf_machine_rel[a],
elf_machine_lazy_rel, and elf_machine_runtime_setup. (This is inspired
by Stan Shebs' ppc64/x86-64 implementation in the
google/grte/v5-2.27/master which uses mixed extra parameters and static
variables.)
Future simplification:
* If mips elf_machine_runtime_setup no longer needs RESOLVE_GOTSYM,
elf_machine_runtime_setup can drop the `scope` parameter.
* If TLSDESC no longer need to be in elf_machine_lazy_rel,
elf_machine_lazy_rel can drop the `scope` parameter.
Tested on aarch64, i386, x86-64, powerpc64le, powerpc64, powerpc32,
sparc64, sparcv9, s390x, s390, hppa, ia64, armhf, alpha, and mips64.
In addition, tested build-many-glibcs.py with {arc,csky,microblaze,nios2}-linux-gnu
and riscv64-linux-gnu-rv64imafdc-lp64d.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-10-07 18:55:02 +00:00
|
|
|
static void __attribute__((always_inline))
|
|
|
|
elf_machine_rela (struct link_map *map, struct r_scope_elem *scope[],
|
2014-04-29 07:08:48 +00:00
|
|
|
const Elf32_Rela *reloc,
|
2011-10-05 09:52:45 +00:00
|
|
|
const Elf32_Sym *sym,
|
2006-05-15 Carlos O'Donell <carlos@systemhalted.org>
* sysdeps/hppa/dl-machine.h: Include tls.h
(elf_machine_fixup_plt): Returns fdesc.
(elf_machine_profile_fixup_plt): Remove.
(elf_machine_plt_value): Returns fdesc.
(elf_machine_runtime_setup): Check that dl_profile != NULL.
(ARCH_LA_PLTENT, ARCH_LA_PLTEXIT): Define.
(RTLD_START): Use iitlbp with sr0.
(elf_machine_type_class): Include TLS relocs.
(reassemble_21, reassemble_14): Define.
(elf_machine_rela): Add DIR21L, DIR14R, PLABEL21L, PLABEL14R,
TLS_DTPMOD32, TLS_TPREL32, TLS_DTPOFF32 support.
(TRAMPOLINE_TEMPLATE): Move to ...
* sysdeps/hppa/dl-trampoline.S: ... here.
* sysdeps/hppa/abort-instr.h: Use iitlbp with sr0.
* sysdeps/hppa/dl-lookupcfg.h: Inlcude dl-fptr.h.
(DL_FIXUP_VALUE_TYPE, DL_FIXUP_MAKE_VALUE, DL_FIXUP_VALUE_CODE_ADDR,
DL_FIXUP_VALUE_ADD, DL_FIXUP_ADDR_VALUE): Define.
* sysdeps/hppa/sysdep.h: Use "!" as a separator. Cleanup comments.
* sysdeps/hppa/bits/link.h (La_hppa_regs, La_hppa_retval): Define.
Define prototypes for la_hppa_gnu_pltenter and la_hppa_gnu_pltexit.
2006-05-14 23:54:47 +00:00
|
|
|
const struct r_found_version *version,
|
2011-10-05 09:52:45 +00:00
|
|
|
void *const reloc_addr_arg,
|
|
|
|
int skip_ifunc)
|
2000-10-15 03:20:01 +00:00
|
|
|
{
|
* elf/dynamic-link.h (elf_machine_rel, elf_machine_rela,
elf_machine_rel_relative, elf_machine_rela_relative): Don't assume
reloc_addr is aligned.
* sysdeps/alpha/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/arm/dl-machine.h (elf_machine_rel, elf_machine_rela,
elf_machine_rel_relative, elf_machine_rela_relative): Adjust.
* sysdeps/cris/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/hppa/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/i386/dl-machine.h (elf_machine_rel, elf_machine_rela,
elf_machine_rel_relative, elf_machine_rela_relative): Adjust.
* sysdeps/ia64/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/m68k/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/mips/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/powerpc/powerpc32/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/powerpc/powerpc64/dl-machine.h
(elf_machine_rela_relative, elf_machine_rela): Adjust.
* sysdeps/s390/s390-32/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/s390/s390-64/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative):
* sysdeps/sh/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/sparc/sparc32/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/sparc/sparc64/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/x86_64/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
2003-07-31 06:33:52 +00:00
|
|
|
Elf32_Addr *const reloc_addr = reloc_addr_arg;
|
2000-10-15 03:20:01 +00:00
|
|
|
const Elf32_Sym *const refsym = sym;
|
|
|
|
unsigned long const r_type = ELF32_R_TYPE (reloc->r_info);
|
|
|
|
struct link_map *sym_map;
|
|
|
|
Elf32_Addr value;
|
|
|
|
|
|
|
|
/* RESOLVE_MAP will return a null value for undefined syms, and
|
|
|
|
non-null for all other syms. In particular, relocs with no
|
|
|
|
symbol (symbol index of zero), also called *ABS* relocs, will be
|
|
|
|
resolved to MAP. (The first entry in a symbol table is all
|
|
|
|
zeros, and an all zero Elf32_Sym has a binding of STB_LOCAL.)
|
|
|
|
See RESOLVE_MAP definition in elf/dl-reloc.c */
|
2004-04-17 22:53:29 +00:00
|
|
|
# ifdef RTLD_BOOTSTRAP
|
elf: Avoid nested functions in the loader [BZ #27220]
dynamic-link.h is included more than once in some elf/ files (rtld.c,
dl-conflict.c, dl-reloc.c, dl-reloc-static-pie.c) and uses GCC nested
functions. This harms readability and the nested functions usage
is the biggest obstacle prevents Clang build (Clang doesn't support GCC
nested functions).
The key idea for unnesting is to add extra parameters (struct link_map
*and struct r_scope_elm *[]) to RESOLVE_MAP,
ELF_MACHINE_BEFORE_RTLD_RELOC, ELF_DYNAMIC_RELOCATE, elf_machine_rel[a],
elf_machine_lazy_rel, and elf_machine_runtime_setup. (This is inspired
by Stan Shebs' ppc64/x86-64 implementation in the
google/grte/v5-2.27/master which uses mixed extra parameters and static
variables.)
Future simplification:
* If mips elf_machine_runtime_setup no longer needs RESOLVE_GOTSYM,
elf_machine_runtime_setup can drop the `scope` parameter.
* If TLSDESC no longer need to be in elf_machine_lazy_rel,
elf_machine_lazy_rel can drop the `scope` parameter.
Tested on aarch64, i386, x86-64, powerpc64le, powerpc64, powerpc32,
sparc64, sparcv9, s390x, s390, hppa, ia64, armhf, alpha, and mips64.
In addition, tested build-many-glibcs.py with {arc,csky,microblaze,nios2}-linux-gnu
and riscv64-linux-gnu-rv64imafdc-lp64d.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-10-07 18:55:02 +00:00
|
|
|
sym_map = map;
|
2004-04-17 22:53:29 +00:00
|
|
|
# else
|
elf: Avoid nested functions in the loader [BZ #27220]
dynamic-link.h is included more than once in some elf/ files (rtld.c,
dl-conflict.c, dl-reloc.c, dl-reloc-static-pie.c) and uses GCC nested
functions. This harms readability and the nested functions usage
is the biggest obstacle prevents Clang build (Clang doesn't support GCC
nested functions).
The key idea for unnesting is to add extra parameters (struct link_map
*and struct r_scope_elm *[]) to RESOLVE_MAP,
ELF_MACHINE_BEFORE_RTLD_RELOC, ELF_DYNAMIC_RELOCATE, elf_machine_rel[a],
elf_machine_lazy_rel, and elf_machine_runtime_setup. (This is inspired
by Stan Shebs' ppc64/x86-64 implementation in the
google/grte/v5-2.27/master which uses mixed extra parameters and static
variables.)
Future simplification:
* If mips elf_machine_runtime_setup no longer needs RESOLVE_GOTSYM,
elf_machine_runtime_setup can drop the `scope` parameter.
* If TLSDESC no longer need to be in elf_machine_lazy_rel,
elf_machine_lazy_rel can drop the `scope` parameter.
Tested on aarch64, i386, x86-64, powerpc64le, powerpc64, powerpc32,
sparc64, sparcv9, s390x, s390, hppa, ia64, armhf, alpha, and mips64.
In addition, tested build-many-glibcs.py with {arc,csky,microblaze,nios2}-linux-gnu
and riscv64-linux-gnu-rv64imafdc-lp64d.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-10-07 18:55:02 +00:00
|
|
|
sym_map = RESOLVE_MAP (map, scope, &sym, version, r_type);
|
2004-04-17 22:53:29 +00:00
|
|
|
# endif
|
2011-10-05 09:52:45 +00:00
|
|
|
|
2000-10-15 03:20:01 +00:00
|
|
|
if (sym_map)
|
|
|
|
{
|
elf: Unify symbol address run-time calculation [BZ #19818]
Wrap symbol address run-time calculation into a macro and use it
throughout, replacing inline calculations.
There are a couple of variants, most of them different in a functionally
insignificant way. Most calculations are right following RESOLVE_MAP,
at which point either the map or the symbol returned can be checked for
validity as the macro sets either both or neither. In some places both
the symbol and the map has to be checked however.
My initial implementation therefore always checked both, however that
resulted in code larger by as much as 0.3%, as many places know from
elsewhere that no check is needed. I have decided the size growth was
unacceptable.
Having looked closer I realized that it's the map that is the culprit.
Therefore I have modified LOOKUP_VALUE_ADDRESS to accept an additional
boolean argument telling it to access the map without checking it for
validity. This in turn has brought quite nice results, with new code
actually being smaller for i686, and MIPS o32, n32 and little-endian n64
targets, unchanged in size for x86-64 and, unusually, marginally larger
for big-endian MIPS n64, as follows:
i686:
text data bss dec hex filename
152255 4052 192 156499 26353 ld-2.27.9000-base.so
152159 4052 192 156403 262f3 ld-2.27.9000-elf-symbol-value.so
MIPS/o32/el:
text data bss dec hex filename
142906 4396 260 147562 2406a ld-2.27.9000-base.so
142890 4396 260 147546 2405a ld-2.27.9000-elf-symbol-value.so
MIPS/n32/el:
text data bss dec hex filename
142267 4404 260 146931 23df3 ld-2.27.9000-base.so
142171 4404 260 146835 23d93 ld-2.27.9000-elf-symbol-value.so
MIPS/n64/el:
text data bss dec hex filename
149835 7376 408 157619 267b3 ld-2.27.9000-base.so
149787 7376 408 157571 26783 ld-2.27.9000-elf-symbol-value.so
MIPS/o32/eb:
text data bss dec hex filename
142870 4396 260 147526 24046 ld-2.27.9000-base.so
142854 4396 260 147510 24036 ld-2.27.9000-elf-symbol-value.so
MIPS/n32/eb:
text data bss dec hex filename
142019 4404 260 146683 23cfb ld-2.27.9000-base.so
141923 4404 260 146587 23c9b ld-2.27.9000-elf-symbol-value.so
MIPS/n64/eb:
text data bss dec hex filename
149763 7376 408 157547 2676b ld-2.27.9000-base.so
149779 7376 408 157563 2677b ld-2.27.9000-elf-symbol-value.so
x86-64:
text data bss dec hex filename
148462 6452 400 155314 25eb2 ld-2.27.9000-base.so
148462 6452 400 155314 25eb2 ld-2.27.9000-elf-symbol-value.so
[BZ #19818]
* sysdeps/generic/ldsodefs.h (LOOKUP_VALUE_ADDRESS): Add `set'
parameter.
(SYMBOL_ADDRESS): New macro.
[!ELF_FUNCTION_PTR_IS_SPECIAL] (DL_SYMBOL_ADDRESS): Use
SYMBOL_ADDRESS for symbol address calculation.
* elf/dl-runtime.c (_dl_fixup): Likewise.
(_dl_profile_fixup): Likewise.
* elf/dl-symaddr.c (_dl_symbol_address): Likewise.
* elf/rtld.c (dl_main): Likewise.
* sysdeps/aarch64/dl-machine.h (elf_machine_rela): Likewise.
* sysdeps/alpha/dl-machine.h (elf_machine_rela): Likewise.
* sysdeps/arm/dl-machine.h (elf_machine_rel): Likewise.
(elf_machine_rela): Likewise.
* sysdeps/hppa/dl-machine.h (elf_machine_rela): Likewise.
* sysdeps/hppa/dl-symaddr.c (_dl_symbol_address): Likewise.
* sysdeps/i386/dl-machine.h (elf_machine_rel): Likewise.
(elf_machine_rela): Likewise.
* sysdeps/ia64/dl-machine.h (elf_machine_rela): Likewise.
* sysdeps/m68k/dl-machine.h (elf_machine_rela): Likewise.
* sysdeps/microblaze/dl-machine.h (elf_machine_rela): Likewise.
* sysdeps/mips/dl-machine.h (ELF_MACHINE_BEFORE_RTLD_RELOC):
Likewise.
(elf_machine_reloc): Likewise.
(elf_machine_got_rel): Likewise.
* sysdeps/mips/dl-trampoline.c (__dl_runtime_resolve): Likewise.
* sysdeps/nios2/dl-machine.h (elf_machine_rela): Likewise.
* sysdeps/powerpc/powerpc32/dl-machine.h (elf_machine_rela):
Likewise.
* sysdeps/powerpc/powerpc64/dl-machine.h (elf_machine_rela):
Likewise.
* sysdeps/riscv/dl-machine.h (elf_machine_rela): Likewise.
* sysdeps/s390/s390-32/dl-machine.h (elf_machine_rela):
Likewise.
* sysdeps/s390/s390-64/dl-machine.h (elf_machine_rela):
Likewise.
* sysdeps/sh/dl-machine.h (elf_machine_rela): Likewise.
* sysdeps/sparc/sparc32/dl-machine.h (elf_machine_rela):
Likewise.
* sysdeps/sparc/sparc64/dl-machine.h (elf_machine_rela):
Likewise.
* sysdeps/tile/dl-machine.h (elf_machine_rela): Likewise.
* sysdeps/x86_64/dl-machine.h (elf_machine_rela): Likewise.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2018-04-04 22:09:37 +00:00
|
|
|
value = SYMBOL_ADDRESS (sym_map, sym, true);
|
2000-10-15 03:20:01 +00:00
|
|
|
value += reloc->r_addend;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
value = 0;
|
|
|
|
|
|
|
|
switch (r_type)
|
|
|
|
{
|
|
|
|
case R_PARISC_DIR32:
|
2001-06-19 00:42:10 +00:00
|
|
|
/* .eh_frame can have unaligned relocs. */
|
* elf/dynamic-link.h (elf_machine_rel, elf_machine_rela,
elf_machine_rel_relative, elf_machine_rela_relative): Don't assume
reloc_addr is aligned.
* sysdeps/alpha/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/arm/dl-machine.h (elf_machine_rel, elf_machine_rela,
elf_machine_rel_relative, elf_machine_rela_relative): Adjust.
* sysdeps/cris/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/hppa/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/i386/dl-machine.h (elf_machine_rel, elf_machine_rela,
elf_machine_rel_relative, elf_machine_rela_relative): Adjust.
* sysdeps/ia64/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/m68k/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/mips/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/powerpc/powerpc32/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/powerpc/powerpc64/dl-machine.h
(elf_machine_rela_relative, elf_machine_rela): Adjust.
* sysdeps/s390/s390-32/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/s390/s390-64/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative):
* sysdeps/sh/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/sparc/sparc32/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/sparc/sparc64/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/x86_64/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
2003-07-31 06:33:52 +00:00
|
|
|
if ((unsigned long) reloc_addr_arg & 3)
|
2001-06-19 00:42:10 +00:00
|
|
|
{
|
* elf/dynamic-link.h (elf_machine_rel, elf_machine_rela,
elf_machine_rel_relative, elf_machine_rela_relative): Don't assume
reloc_addr is aligned.
* sysdeps/alpha/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/arm/dl-machine.h (elf_machine_rel, elf_machine_rela,
elf_machine_rel_relative, elf_machine_rela_relative): Adjust.
* sysdeps/cris/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/hppa/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/i386/dl-machine.h (elf_machine_rel, elf_machine_rela,
elf_machine_rel_relative, elf_machine_rela_relative): Adjust.
* sysdeps/ia64/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/m68k/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/mips/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/powerpc/powerpc32/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/powerpc/powerpc64/dl-machine.h
(elf_machine_rela_relative, elf_machine_rela): Adjust.
* sysdeps/s390/s390-32/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/s390/s390-64/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative):
* sysdeps/sh/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/sparc/sparc32/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/sparc/sparc64/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/x86_64/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
2003-07-31 06:33:52 +00:00
|
|
|
char *rel_addr = (char *) reloc_addr_arg;
|
2001-06-19 00:42:10 +00:00
|
|
|
rel_addr[0] = value >> 24;
|
|
|
|
rel_addr[1] = value >> 16;
|
|
|
|
rel_addr[2] = value >> 8;
|
|
|
|
rel_addr[3] = value;
|
|
|
|
return;
|
|
|
|
}
|
2000-10-15 03:20:01 +00:00
|
|
|
break;
|
|
|
|
|
2006-05-15 Carlos O'Donell <carlos@systemhalted.org>
* sysdeps/hppa/dl-machine.h: Include tls.h
(elf_machine_fixup_plt): Returns fdesc.
(elf_machine_profile_fixup_plt): Remove.
(elf_machine_plt_value): Returns fdesc.
(elf_machine_runtime_setup): Check that dl_profile != NULL.
(ARCH_LA_PLTENT, ARCH_LA_PLTEXIT): Define.
(RTLD_START): Use iitlbp with sr0.
(elf_machine_type_class): Include TLS relocs.
(reassemble_21, reassemble_14): Define.
(elf_machine_rela): Add DIR21L, DIR14R, PLABEL21L, PLABEL14R,
TLS_DTPMOD32, TLS_TPREL32, TLS_DTPOFF32 support.
(TRAMPOLINE_TEMPLATE): Move to ...
* sysdeps/hppa/dl-trampoline.S: ... here.
* sysdeps/hppa/abort-instr.h: Use iitlbp with sr0.
* sysdeps/hppa/dl-lookupcfg.h: Inlcude dl-fptr.h.
(DL_FIXUP_VALUE_TYPE, DL_FIXUP_MAKE_VALUE, DL_FIXUP_VALUE_CODE_ADDR,
DL_FIXUP_VALUE_ADD, DL_FIXUP_ADDR_VALUE): Define.
* sysdeps/hppa/sysdep.h: Use "!" as a separator. Cleanup comments.
* sysdeps/hppa/bits/link.h (La_hppa_regs, La_hppa_retval): Define.
Define prototypes for la_hppa_gnu_pltenter and la_hppa_gnu_pltexit.
2006-05-14 23:54:47 +00:00
|
|
|
case R_PARISC_DIR21L:
|
|
|
|
{
|
|
|
|
unsigned int insn = *(unsigned int *)reloc_addr;
|
elf: Unify symbol address run-time calculation [BZ #19818]
Wrap symbol address run-time calculation into a macro and use it
throughout, replacing inline calculations.
There are a couple of variants, most of them different in a functionally
insignificant way. Most calculations are right following RESOLVE_MAP,
at which point either the map or the symbol returned can be checked for
validity as the macro sets either both or neither. In some places both
the symbol and the map has to be checked however.
My initial implementation therefore always checked both, however that
resulted in code larger by as much as 0.3%, as many places know from
elsewhere that no check is needed. I have decided the size growth was
unacceptable.
Having looked closer I realized that it's the map that is the culprit.
Therefore I have modified LOOKUP_VALUE_ADDRESS to accept an additional
boolean argument telling it to access the map without checking it for
validity. This in turn has brought quite nice results, with new code
actually being smaller for i686, and MIPS o32, n32 and little-endian n64
targets, unchanged in size for x86-64 and, unusually, marginally larger
for big-endian MIPS n64, as follows:
i686:
text data bss dec hex filename
152255 4052 192 156499 26353 ld-2.27.9000-base.so
152159 4052 192 156403 262f3 ld-2.27.9000-elf-symbol-value.so
MIPS/o32/el:
text data bss dec hex filename
142906 4396 260 147562 2406a ld-2.27.9000-base.so
142890 4396 260 147546 2405a ld-2.27.9000-elf-symbol-value.so
MIPS/n32/el:
text data bss dec hex filename
142267 4404 260 146931 23df3 ld-2.27.9000-base.so
142171 4404 260 146835 23d93 ld-2.27.9000-elf-symbol-value.so
MIPS/n64/el:
text data bss dec hex filename
149835 7376 408 157619 267b3 ld-2.27.9000-base.so
149787 7376 408 157571 26783 ld-2.27.9000-elf-symbol-value.so
MIPS/o32/eb:
text data bss dec hex filename
142870 4396 260 147526 24046 ld-2.27.9000-base.so
142854 4396 260 147510 24036 ld-2.27.9000-elf-symbol-value.so
MIPS/n32/eb:
text data bss dec hex filename
142019 4404 260 146683 23cfb ld-2.27.9000-base.so
141923 4404 260 146587 23c9b ld-2.27.9000-elf-symbol-value.so
MIPS/n64/eb:
text data bss dec hex filename
149763 7376 408 157547 2676b ld-2.27.9000-base.so
149779 7376 408 157563 2677b ld-2.27.9000-elf-symbol-value.so
x86-64:
text data bss dec hex filename
148462 6452 400 155314 25eb2 ld-2.27.9000-base.so
148462 6452 400 155314 25eb2 ld-2.27.9000-elf-symbol-value.so
[BZ #19818]
* sysdeps/generic/ldsodefs.h (LOOKUP_VALUE_ADDRESS): Add `set'
parameter.
(SYMBOL_ADDRESS): New macro.
[!ELF_FUNCTION_PTR_IS_SPECIAL] (DL_SYMBOL_ADDRESS): Use
SYMBOL_ADDRESS for symbol address calculation.
* elf/dl-runtime.c (_dl_fixup): Likewise.
(_dl_profile_fixup): Likewise.
* elf/dl-symaddr.c (_dl_symbol_address): Likewise.
* elf/rtld.c (dl_main): Likewise.
* sysdeps/aarch64/dl-machine.h (elf_machine_rela): Likewise.
* sysdeps/alpha/dl-machine.h (elf_machine_rela): Likewise.
* sysdeps/arm/dl-machine.h (elf_machine_rel): Likewise.
(elf_machine_rela): Likewise.
* sysdeps/hppa/dl-machine.h (elf_machine_rela): Likewise.
* sysdeps/hppa/dl-symaddr.c (_dl_symbol_address): Likewise.
* sysdeps/i386/dl-machine.h (elf_machine_rel): Likewise.
(elf_machine_rela): Likewise.
* sysdeps/ia64/dl-machine.h (elf_machine_rela): Likewise.
* sysdeps/m68k/dl-machine.h (elf_machine_rela): Likewise.
* sysdeps/microblaze/dl-machine.h (elf_machine_rela): Likewise.
* sysdeps/mips/dl-machine.h (ELF_MACHINE_BEFORE_RTLD_RELOC):
Likewise.
(elf_machine_reloc): Likewise.
(elf_machine_got_rel): Likewise.
* sysdeps/mips/dl-trampoline.c (__dl_runtime_resolve): Likewise.
* sysdeps/nios2/dl-machine.h (elf_machine_rela): Likewise.
* sysdeps/powerpc/powerpc32/dl-machine.h (elf_machine_rela):
Likewise.
* sysdeps/powerpc/powerpc64/dl-machine.h (elf_machine_rela):
Likewise.
* sysdeps/riscv/dl-machine.h (elf_machine_rela): Likewise.
* sysdeps/s390/s390-32/dl-machine.h (elf_machine_rela):
Likewise.
* sysdeps/s390/s390-64/dl-machine.h (elf_machine_rela):
Likewise.
* sysdeps/sh/dl-machine.h (elf_machine_rela): Likewise.
* sysdeps/sparc/sparc32/dl-machine.h (elf_machine_rela):
Likewise.
* sysdeps/sparc/sparc64/dl-machine.h (elf_machine_rela):
Likewise.
* sysdeps/tile/dl-machine.h (elf_machine_rela): Likewise.
* sysdeps/x86_64/dl-machine.h (elf_machine_rela): Likewise.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2018-04-04 22:09:37 +00:00
|
|
|
value = (SYMBOL_ADDRESS (sym_map, sym, true)
|
|
|
|
+ ((reloc->r_addend + 0x1000) & -0x2000));
|
2006-05-15 Carlos O'Donell <carlos@systemhalted.org>
* sysdeps/hppa/dl-machine.h: Include tls.h
(elf_machine_fixup_plt): Returns fdesc.
(elf_machine_profile_fixup_plt): Remove.
(elf_machine_plt_value): Returns fdesc.
(elf_machine_runtime_setup): Check that dl_profile != NULL.
(ARCH_LA_PLTENT, ARCH_LA_PLTEXIT): Define.
(RTLD_START): Use iitlbp with sr0.
(elf_machine_type_class): Include TLS relocs.
(reassemble_21, reassemble_14): Define.
(elf_machine_rela): Add DIR21L, DIR14R, PLABEL21L, PLABEL14R,
TLS_DTPMOD32, TLS_TPREL32, TLS_DTPOFF32 support.
(TRAMPOLINE_TEMPLATE): Move to ...
* sysdeps/hppa/dl-trampoline.S: ... here.
* sysdeps/hppa/abort-instr.h: Use iitlbp with sr0.
* sysdeps/hppa/dl-lookupcfg.h: Inlcude dl-fptr.h.
(DL_FIXUP_VALUE_TYPE, DL_FIXUP_MAKE_VALUE, DL_FIXUP_VALUE_CODE_ADDR,
DL_FIXUP_VALUE_ADD, DL_FIXUP_ADDR_VALUE): Define.
* sysdeps/hppa/sysdep.h: Use "!" as a separator. Cleanup comments.
* sysdeps/hppa/bits/link.h (La_hppa_regs, La_hppa_retval): Define.
Define prototypes for la_hppa_gnu_pltenter and la_hppa_gnu_pltexit.
2006-05-14 23:54:47 +00:00
|
|
|
value = value >> 11;
|
|
|
|
insn = (insn &~ 0x1fffff) | reassemble_21 (value);
|
|
|
|
*(unsigned int *)reloc_addr = insn;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
case R_PARISC_DIR14R:
|
|
|
|
{
|
|
|
|
unsigned int insn = *(unsigned int *)reloc_addr;
|
elf: Unify symbol address run-time calculation [BZ #19818]
Wrap symbol address run-time calculation into a macro and use it
throughout, replacing inline calculations.
There are a couple of variants, most of them different in a functionally
insignificant way. Most calculations are right following RESOLVE_MAP,
at which point either the map or the symbol returned can be checked for
validity as the macro sets either both or neither. In some places both
the symbol and the map has to be checked however.
My initial implementation therefore always checked both, however that
resulted in code larger by as much as 0.3%, as many places know from
elsewhere that no check is needed. I have decided the size growth was
unacceptable.
Having looked closer I realized that it's the map that is the culprit.
Therefore I have modified LOOKUP_VALUE_ADDRESS to accept an additional
boolean argument telling it to access the map without checking it for
validity. This in turn has brought quite nice results, with new code
actually being smaller for i686, and MIPS o32, n32 and little-endian n64
targets, unchanged in size for x86-64 and, unusually, marginally larger
for big-endian MIPS n64, as follows:
i686:
text data bss dec hex filename
152255 4052 192 156499 26353 ld-2.27.9000-base.so
152159 4052 192 156403 262f3 ld-2.27.9000-elf-symbol-value.so
MIPS/o32/el:
text data bss dec hex filename
142906 4396 260 147562 2406a ld-2.27.9000-base.so
142890 4396 260 147546 2405a ld-2.27.9000-elf-symbol-value.so
MIPS/n32/el:
text data bss dec hex filename
142267 4404 260 146931 23df3 ld-2.27.9000-base.so
142171 4404 260 146835 23d93 ld-2.27.9000-elf-symbol-value.so
MIPS/n64/el:
text data bss dec hex filename
149835 7376 408 157619 267b3 ld-2.27.9000-base.so
149787 7376 408 157571 26783 ld-2.27.9000-elf-symbol-value.so
MIPS/o32/eb:
text data bss dec hex filename
142870 4396 260 147526 24046 ld-2.27.9000-base.so
142854 4396 260 147510 24036 ld-2.27.9000-elf-symbol-value.so
MIPS/n32/eb:
text data bss dec hex filename
142019 4404 260 146683 23cfb ld-2.27.9000-base.so
141923 4404 260 146587 23c9b ld-2.27.9000-elf-symbol-value.so
MIPS/n64/eb:
text data bss dec hex filename
149763 7376 408 157547 2676b ld-2.27.9000-base.so
149779 7376 408 157563 2677b ld-2.27.9000-elf-symbol-value.so
x86-64:
text data bss dec hex filename
148462 6452 400 155314 25eb2 ld-2.27.9000-base.so
148462 6452 400 155314 25eb2 ld-2.27.9000-elf-symbol-value.so
[BZ #19818]
* sysdeps/generic/ldsodefs.h (LOOKUP_VALUE_ADDRESS): Add `set'
parameter.
(SYMBOL_ADDRESS): New macro.
[!ELF_FUNCTION_PTR_IS_SPECIAL] (DL_SYMBOL_ADDRESS): Use
SYMBOL_ADDRESS for symbol address calculation.
* elf/dl-runtime.c (_dl_fixup): Likewise.
(_dl_profile_fixup): Likewise.
* elf/dl-symaddr.c (_dl_symbol_address): Likewise.
* elf/rtld.c (dl_main): Likewise.
* sysdeps/aarch64/dl-machine.h (elf_machine_rela): Likewise.
* sysdeps/alpha/dl-machine.h (elf_machine_rela): Likewise.
* sysdeps/arm/dl-machine.h (elf_machine_rel): Likewise.
(elf_machine_rela): Likewise.
* sysdeps/hppa/dl-machine.h (elf_machine_rela): Likewise.
* sysdeps/hppa/dl-symaddr.c (_dl_symbol_address): Likewise.
* sysdeps/i386/dl-machine.h (elf_machine_rel): Likewise.
(elf_machine_rela): Likewise.
* sysdeps/ia64/dl-machine.h (elf_machine_rela): Likewise.
* sysdeps/m68k/dl-machine.h (elf_machine_rela): Likewise.
* sysdeps/microblaze/dl-machine.h (elf_machine_rela): Likewise.
* sysdeps/mips/dl-machine.h (ELF_MACHINE_BEFORE_RTLD_RELOC):
Likewise.
(elf_machine_reloc): Likewise.
(elf_machine_got_rel): Likewise.
* sysdeps/mips/dl-trampoline.c (__dl_runtime_resolve): Likewise.
* sysdeps/nios2/dl-machine.h (elf_machine_rela): Likewise.
* sysdeps/powerpc/powerpc32/dl-machine.h (elf_machine_rela):
Likewise.
* sysdeps/powerpc/powerpc64/dl-machine.h (elf_machine_rela):
Likewise.
* sysdeps/riscv/dl-machine.h (elf_machine_rela): Likewise.
* sysdeps/s390/s390-32/dl-machine.h (elf_machine_rela):
Likewise.
* sysdeps/s390/s390-64/dl-machine.h (elf_machine_rela):
Likewise.
* sysdeps/sh/dl-machine.h (elf_machine_rela): Likewise.
* sysdeps/sparc/sparc32/dl-machine.h (elf_machine_rela):
Likewise.
* sysdeps/sparc/sparc64/dl-machine.h (elf_machine_rela):
Likewise.
* sysdeps/tile/dl-machine.h (elf_machine_rela): Likewise.
* sysdeps/x86_64/dl-machine.h (elf_machine_rela): Likewise.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2018-04-04 22:09:37 +00:00
|
|
|
value = ((SYMBOL_ADDRESS (sym_map, sym, true) & 0x7ff)
|
|
|
|
+ (((reloc->r_addend & 0x1fff) ^ 0x1000) - 0x1000));
|
2006-05-15 Carlos O'Donell <carlos@systemhalted.org>
* sysdeps/hppa/dl-machine.h: Include tls.h
(elf_machine_fixup_plt): Returns fdesc.
(elf_machine_profile_fixup_plt): Remove.
(elf_machine_plt_value): Returns fdesc.
(elf_machine_runtime_setup): Check that dl_profile != NULL.
(ARCH_LA_PLTENT, ARCH_LA_PLTEXIT): Define.
(RTLD_START): Use iitlbp with sr0.
(elf_machine_type_class): Include TLS relocs.
(reassemble_21, reassemble_14): Define.
(elf_machine_rela): Add DIR21L, DIR14R, PLABEL21L, PLABEL14R,
TLS_DTPMOD32, TLS_TPREL32, TLS_DTPOFF32 support.
(TRAMPOLINE_TEMPLATE): Move to ...
* sysdeps/hppa/dl-trampoline.S: ... here.
* sysdeps/hppa/abort-instr.h: Use iitlbp with sr0.
* sysdeps/hppa/dl-lookupcfg.h: Inlcude dl-fptr.h.
(DL_FIXUP_VALUE_TYPE, DL_FIXUP_MAKE_VALUE, DL_FIXUP_VALUE_CODE_ADDR,
DL_FIXUP_VALUE_ADD, DL_FIXUP_ADDR_VALUE): Define.
* sysdeps/hppa/sysdep.h: Use "!" as a separator. Cleanup comments.
* sysdeps/hppa/bits/link.h (La_hppa_regs, La_hppa_retval): Define.
Define prototypes for la_hppa_gnu_pltenter and la_hppa_gnu_pltexit.
2006-05-14 23:54:47 +00:00
|
|
|
insn = (insn &~ 0x3fff) | reassemble_14 (value);
|
|
|
|
*(unsigned int *)reloc_addr = insn;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
2000-10-15 03:20:01 +00:00
|
|
|
case R_PARISC_PLABEL32:
|
|
|
|
/* Easy rule: If there is a symbol and it is global, then we
|
2011-10-05 09:52:45 +00:00
|
|
|
need to make a dynamic function descriptor. Otherwise we
|
|
|
|
have the address of a PLT slot for a local symbol which we
|
|
|
|
know to be unique. */
|
2000-10-15 03:20:01 +00:00
|
|
|
if (sym == NULL
|
|
|
|
|| sym_map == NULL
|
|
|
|
|| ELF32_ST_BIND (sym->st_info) == STB_LOCAL)
|
2011-10-05 09:52:45 +00:00
|
|
|
{
|
2004-04-17 22:53:29 +00:00
|
|
|
break;
|
2011-10-05 09:52:45 +00:00
|
|
|
}
|
2004-04-17 22:53:29 +00:00
|
|
|
/* Set bit 30 to indicate to $$dyncall that this is a PLABEL.
|
2011-10-05 09:52:45 +00:00
|
|
|
We have to do this outside of the generic function descriptor
|
2004-04-17 22:53:29 +00:00
|
|
|
code, since it doesn't know about our requirement for setting
|
|
|
|
protection bits */
|
|
|
|
value = (Elf32_Addr)((unsigned int)_dl_make_fptr (sym_map, sym, value) | 2);
|
2000-10-15 03:20:01 +00:00
|
|
|
break;
|
|
|
|
|
2006-05-15 Carlos O'Donell <carlos@systemhalted.org>
* sysdeps/hppa/dl-machine.h: Include tls.h
(elf_machine_fixup_plt): Returns fdesc.
(elf_machine_profile_fixup_plt): Remove.
(elf_machine_plt_value): Returns fdesc.
(elf_machine_runtime_setup): Check that dl_profile != NULL.
(ARCH_LA_PLTENT, ARCH_LA_PLTEXIT): Define.
(RTLD_START): Use iitlbp with sr0.
(elf_machine_type_class): Include TLS relocs.
(reassemble_21, reassemble_14): Define.
(elf_machine_rela): Add DIR21L, DIR14R, PLABEL21L, PLABEL14R,
TLS_DTPMOD32, TLS_TPREL32, TLS_DTPOFF32 support.
(TRAMPOLINE_TEMPLATE): Move to ...
* sysdeps/hppa/dl-trampoline.S: ... here.
* sysdeps/hppa/abort-instr.h: Use iitlbp with sr0.
* sysdeps/hppa/dl-lookupcfg.h: Inlcude dl-fptr.h.
(DL_FIXUP_VALUE_TYPE, DL_FIXUP_MAKE_VALUE, DL_FIXUP_VALUE_CODE_ADDR,
DL_FIXUP_VALUE_ADD, DL_FIXUP_ADDR_VALUE): Define.
* sysdeps/hppa/sysdep.h: Use "!" as a separator. Cleanup comments.
* sysdeps/hppa/bits/link.h (La_hppa_regs, La_hppa_retval): Define.
Define prototypes for la_hppa_gnu_pltenter and la_hppa_gnu_pltexit.
2006-05-14 23:54:47 +00:00
|
|
|
case R_PARISC_PLABEL21L:
|
|
|
|
case R_PARISC_PLABEL14R:
|
|
|
|
{
|
|
|
|
unsigned int insn = *(unsigned int *)reloc_addr;
|
|
|
|
|
2011-10-05 09:52:45 +00:00
|
|
|
if (__builtin_expect (sym == NULL, 0))
|
|
|
|
break;
|
2006-05-15 Carlos O'Donell <carlos@systemhalted.org>
* sysdeps/hppa/dl-machine.h: Include tls.h
(elf_machine_fixup_plt): Returns fdesc.
(elf_machine_profile_fixup_plt): Remove.
(elf_machine_plt_value): Returns fdesc.
(elf_machine_runtime_setup): Check that dl_profile != NULL.
(ARCH_LA_PLTENT, ARCH_LA_PLTEXIT): Define.
(RTLD_START): Use iitlbp with sr0.
(elf_machine_type_class): Include TLS relocs.
(reassemble_21, reassemble_14): Define.
(elf_machine_rela): Add DIR21L, DIR14R, PLABEL21L, PLABEL14R,
TLS_DTPMOD32, TLS_TPREL32, TLS_DTPOFF32 support.
(TRAMPOLINE_TEMPLATE): Move to ...
* sysdeps/hppa/dl-trampoline.S: ... here.
* sysdeps/hppa/abort-instr.h: Use iitlbp with sr0.
* sysdeps/hppa/dl-lookupcfg.h: Inlcude dl-fptr.h.
(DL_FIXUP_VALUE_TYPE, DL_FIXUP_MAKE_VALUE, DL_FIXUP_VALUE_CODE_ADDR,
DL_FIXUP_VALUE_ADD, DL_FIXUP_ADDR_VALUE): Define.
* sysdeps/hppa/sysdep.h: Use "!" as a separator. Cleanup comments.
* sysdeps/hppa/bits/link.h (La_hppa_regs, La_hppa_retval): Define.
Define prototypes for la_hppa_gnu_pltenter and la_hppa_gnu_pltexit.
2006-05-14 23:54:47 +00:00
|
|
|
|
2011-10-05 09:52:45 +00:00
|
|
|
value = (Elf32_Addr)((unsigned int)_dl_make_fptr (sym_map, sym, value) | 2);
|
2006-05-15 Carlos O'Donell <carlos@systemhalted.org>
* sysdeps/hppa/dl-machine.h: Include tls.h
(elf_machine_fixup_plt): Returns fdesc.
(elf_machine_profile_fixup_plt): Remove.
(elf_machine_plt_value): Returns fdesc.
(elf_machine_runtime_setup): Check that dl_profile != NULL.
(ARCH_LA_PLTENT, ARCH_LA_PLTEXIT): Define.
(RTLD_START): Use iitlbp with sr0.
(elf_machine_type_class): Include TLS relocs.
(reassemble_21, reassemble_14): Define.
(elf_machine_rela): Add DIR21L, DIR14R, PLABEL21L, PLABEL14R,
TLS_DTPMOD32, TLS_TPREL32, TLS_DTPOFF32 support.
(TRAMPOLINE_TEMPLATE): Move to ...
* sysdeps/hppa/dl-trampoline.S: ... here.
* sysdeps/hppa/abort-instr.h: Use iitlbp with sr0.
* sysdeps/hppa/dl-lookupcfg.h: Inlcude dl-fptr.h.
(DL_FIXUP_VALUE_TYPE, DL_FIXUP_MAKE_VALUE, DL_FIXUP_VALUE_CODE_ADDR,
DL_FIXUP_VALUE_ADD, DL_FIXUP_ADDR_VALUE): Define.
* sysdeps/hppa/sysdep.h: Use "!" as a separator. Cleanup comments.
* sysdeps/hppa/bits/link.h (La_hppa_regs, La_hppa_retval): Define.
Define prototypes for la_hppa_gnu_pltenter and la_hppa_gnu_pltexit.
2006-05-14 23:54:47 +00:00
|
|
|
|
2011-10-05 09:52:45 +00:00
|
|
|
if (r_type == R_PARISC_PLABEL21L)
|
2006-05-15 Carlos O'Donell <carlos@systemhalted.org>
* sysdeps/hppa/dl-machine.h: Include tls.h
(elf_machine_fixup_plt): Returns fdesc.
(elf_machine_profile_fixup_plt): Remove.
(elf_machine_plt_value): Returns fdesc.
(elf_machine_runtime_setup): Check that dl_profile != NULL.
(ARCH_LA_PLTENT, ARCH_LA_PLTEXIT): Define.
(RTLD_START): Use iitlbp with sr0.
(elf_machine_type_class): Include TLS relocs.
(reassemble_21, reassemble_14): Define.
(elf_machine_rela): Add DIR21L, DIR14R, PLABEL21L, PLABEL14R,
TLS_DTPMOD32, TLS_TPREL32, TLS_DTPOFF32 support.
(TRAMPOLINE_TEMPLATE): Move to ...
* sysdeps/hppa/dl-trampoline.S: ... here.
* sysdeps/hppa/abort-instr.h: Use iitlbp with sr0.
* sysdeps/hppa/dl-lookupcfg.h: Inlcude dl-fptr.h.
(DL_FIXUP_VALUE_TYPE, DL_FIXUP_MAKE_VALUE, DL_FIXUP_VALUE_CODE_ADDR,
DL_FIXUP_VALUE_ADD, DL_FIXUP_ADDR_VALUE): Define.
* sysdeps/hppa/sysdep.h: Use "!" as a separator. Cleanup comments.
* sysdeps/hppa/bits/link.h (La_hppa_regs, La_hppa_retval): Define.
Define prototypes for la_hppa_gnu_pltenter and la_hppa_gnu_pltexit.
2006-05-14 23:54:47 +00:00
|
|
|
{
|
|
|
|
value >>= 11;
|
|
|
|
insn = (insn &~ 0x1fffff) | reassemble_21 (value);
|
|
|
|
}
|
2011-10-05 09:52:45 +00:00
|
|
|
else
|
2006-05-15 Carlos O'Donell <carlos@systemhalted.org>
* sysdeps/hppa/dl-machine.h: Include tls.h
(elf_machine_fixup_plt): Returns fdesc.
(elf_machine_profile_fixup_plt): Remove.
(elf_machine_plt_value): Returns fdesc.
(elf_machine_runtime_setup): Check that dl_profile != NULL.
(ARCH_LA_PLTENT, ARCH_LA_PLTEXIT): Define.
(RTLD_START): Use iitlbp with sr0.
(elf_machine_type_class): Include TLS relocs.
(reassemble_21, reassemble_14): Define.
(elf_machine_rela): Add DIR21L, DIR14R, PLABEL21L, PLABEL14R,
TLS_DTPMOD32, TLS_TPREL32, TLS_DTPOFF32 support.
(TRAMPOLINE_TEMPLATE): Move to ...
* sysdeps/hppa/dl-trampoline.S: ... here.
* sysdeps/hppa/abort-instr.h: Use iitlbp with sr0.
* sysdeps/hppa/dl-lookupcfg.h: Inlcude dl-fptr.h.
(DL_FIXUP_VALUE_TYPE, DL_FIXUP_MAKE_VALUE, DL_FIXUP_VALUE_CODE_ADDR,
DL_FIXUP_VALUE_ADD, DL_FIXUP_ADDR_VALUE): Define.
* sysdeps/hppa/sysdep.h: Use "!" as a separator. Cleanup comments.
* sysdeps/hppa/bits/link.h (La_hppa_regs, La_hppa_retval): Define.
Define prototypes for la_hppa_gnu_pltenter and la_hppa_gnu_pltexit.
2006-05-14 23:54:47 +00:00
|
|
|
{
|
|
|
|
value &= 0x7ff;
|
|
|
|
insn = (insn &~ 0x3fff) | reassemble_14 (value);
|
|
|
|
}
|
|
|
|
|
|
|
|
*(unsigned int *)reloc_addr = insn;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
2000-10-15 03:20:01 +00:00
|
|
|
case R_PARISC_IPLT:
|
|
|
|
if (__builtin_expect (sym_map != NULL, 1))
|
2011-10-05 09:52:45 +00:00
|
|
|
{
|
2017-07-13 00:02:45 +00:00
|
|
|
elf_machine_fixup_plt (NULL, sym_map, NULL, NULL, reloc, reloc_addr,
|
2014-04-29 07:08:48 +00:00
|
|
|
DL_FIXUP_MAKE_VALUE(sym_map, value));
|
2011-10-05 09:52:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-10-15 03:20:01 +00:00
|
|
|
/* If we get here, it's a (weak) undefined sym. */
|
2017-06-14 01:17:25 +00:00
|
|
|
elf_machine_fixup_plt (NULL, map, NULL, NULL, reloc, reloc_addr,
|
2014-04-29 07:08:48 +00:00
|
|
|
DL_FIXUP_MAKE_VALUE(map, value));
|
2011-10-05 09:52:45 +00:00
|
|
|
}
|
2000-10-15 03:20:01 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
case R_PARISC_COPY:
|
|
|
|
if (__builtin_expect (sym == NULL, 0))
|
|
|
|
/* This can happen in trace mode if an object could not be
|
|
|
|
found. */
|
|
|
|
break;
|
|
|
|
if (__builtin_expect (sym->st_size > refsym->st_size, 0)
|
|
|
|
|| (__builtin_expect (sym->st_size < refsym->st_size, 0)
|
2004-04-17 22:53:29 +00:00
|
|
|
&& __builtin_expect (GLRO(dl_verbose), 0)))
|
2000-10-15 03:20:01 +00:00
|
|
|
{
|
|
|
|
const char *strtab;
|
|
|
|
|
|
|
|
strtab = (const char *) D_PTR (map, l_info[DT_STRTAB]);
|
2004-04-17 22:53:29 +00:00
|
|
|
_dl_error_printf ("%s: Symbol `%s' has different size in shared object, "
|
|
|
|
"consider re-linking\n",
|
2013-05-29 16:00:20 +00:00
|
|
|
RTLD_PROGNAME, strtab + refsym->st_name);
|
2000-10-15 03:20:01 +00:00
|
|
|
}
|
* elf/dynamic-link.h (elf_machine_rel, elf_machine_rela,
elf_machine_rel_relative, elf_machine_rela_relative): Don't assume
reloc_addr is aligned.
* sysdeps/alpha/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/arm/dl-machine.h (elf_machine_rel, elf_machine_rela,
elf_machine_rel_relative, elf_machine_rela_relative): Adjust.
* sysdeps/cris/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/hppa/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/i386/dl-machine.h (elf_machine_rel, elf_machine_rela,
elf_machine_rel_relative, elf_machine_rela_relative): Adjust.
* sysdeps/ia64/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/m68k/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/mips/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/powerpc/powerpc32/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/powerpc/powerpc64/dl-machine.h
(elf_machine_rela_relative, elf_machine_rela): Adjust.
* sysdeps/s390/s390-32/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/s390/s390-64/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative):
* sysdeps/sh/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/sparc/sparc32/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/sparc/sparc64/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/x86_64/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
2003-07-31 06:33:52 +00:00
|
|
|
memcpy (reloc_addr_arg, (void *) value,
|
2000-10-15 03:20:01 +00:00
|
|
|
MIN (sym->st_size, refsym->st_size));
|
|
|
|
return;
|
2006-05-15 Carlos O'Donell <carlos@systemhalted.org>
* sysdeps/hppa/dl-machine.h: Include tls.h
(elf_machine_fixup_plt): Returns fdesc.
(elf_machine_profile_fixup_plt): Remove.
(elf_machine_plt_value): Returns fdesc.
(elf_machine_runtime_setup): Check that dl_profile != NULL.
(ARCH_LA_PLTENT, ARCH_LA_PLTEXIT): Define.
(RTLD_START): Use iitlbp with sr0.
(elf_machine_type_class): Include TLS relocs.
(reassemble_21, reassemble_14): Define.
(elf_machine_rela): Add DIR21L, DIR14R, PLABEL21L, PLABEL14R,
TLS_DTPMOD32, TLS_TPREL32, TLS_DTPOFF32 support.
(TRAMPOLINE_TEMPLATE): Move to ...
* sysdeps/hppa/dl-trampoline.S: ... here.
* sysdeps/hppa/abort-instr.h: Use iitlbp with sr0.
* sysdeps/hppa/dl-lookupcfg.h: Inlcude dl-fptr.h.
(DL_FIXUP_VALUE_TYPE, DL_FIXUP_MAKE_VALUE, DL_FIXUP_VALUE_CODE_ADDR,
DL_FIXUP_VALUE_ADD, DL_FIXUP_ADDR_VALUE): Define.
* sysdeps/hppa/sysdep.h: Use "!" as a separator. Cleanup comments.
* sysdeps/hppa/bits/link.h (La_hppa_regs, La_hppa_retval): Define.
Define prototypes for la_hppa_gnu_pltenter and la_hppa_gnu_pltexit.
2006-05-14 23:54:47 +00:00
|
|
|
|
2015-08-15 02:07:40 +00:00
|
|
|
#if !defined RTLD_BOOTSTRAP
|
2006-05-15 Carlos O'Donell <carlos@systemhalted.org>
* sysdeps/hppa/dl-machine.h: Include tls.h
(elf_machine_fixup_plt): Returns fdesc.
(elf_machine_profile_fixup_plt): Remove.
(elf_machine_plt_value): Returns fdesc.
(elf_machine_runtime_setup): Check that dl_profile != NULL.
(ARCH_LA_PLTENT, ARCH_LA_PLTEXIT): Define.
(RTLD_START): Use iitlbp with sr0.
(elf_machine_type_class): Include TLS relocs.
(reassemble_21, reassemble_14): Define.
(elf_machine_rela): Add DIR21L, DIR14R, PLABEL21L, PLABEL14R,
TLS_DTPMOD32, TLS_TPREL32, TLS_DTPOFF32 support.
(TRAMPOLINE_TEMPLATE): Move to ...
* sysdeps/hppa/dl-trampoline.S: ... here.
* sysdeps/hppa/abort-instr.h: Use iitlbp with sr0.
* sysdeps/hppa/dl-lookupcfg.h: Inlcude dl-fptr.h.
(DL_FIXUP_VALUE_TYPE, DL_FIXUP_MAKE_VALUE, DL_FIXUP_VALUE_CODE_ADDR,
DL_FIXUP_VALUE_ADD, DL_FIXUP_ADDR_VALUE): Define.
* sysdeps/hppa/sysdep.h: Use "!" as a separator. Cleanup comments.
* sysdeps/hppa/bits/link.h (La_hppa_regs, La_hppa_retval): Define.
Define prototypes for la_hppa_gnu_pltenter and la_hppa_gnu_pltexit.
2006-05-14 23:54:47 +00:00
|
|
|
case R_PARISC_TLS_DTPMOD32:
|
|
|
|
value = sym_map->l_tls_modid;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case R_PARISC_TLS_DTPOFF32:
|
|
|
|
/* During relocation all TLS symbols are defined and used.
|
2011-10-05 09:52:45 +00:00
|
|
|
Therefore the offset is already correct. */
|
2006-05-15 Carlos O'Donell <carlos@systemhalted.org>
* sysdeps/hppa/dl-machine.h: Include tls.h
(elf_machine_fixup_plt): Returns fdesc.
(elf_machine_profile_fixup_plt): Remove.
(elf_machine_plt_value): Returns fdesc.
(elf_machine_runtime_setup): Check that dl_profile != NULL.
(ARCH_LA_PLTENT, ARCH_LA_PLTEXIT): Define.
(RTLD_START): Use iitlbp with sr0.
(elf_machine_type_class): Include TLS relocs.
(reassemble_21, reassemble_14): Define.
(elf_machine_rela): Add DIR21L, DIR14R, PLABEL21L, PLABEL14R,
TLS_DTPMOD32, TLS_TPREL32, TLS_DTPOFF32 support.
(TRAMPOLINE_TEMPLATE): Move to ...
* sysdeps/hppa/dl-trampoline.S: ... here.
* sysdeps/hppa/abort-instr.h: Use iitlbp with sr0.
* sysdeps/hppa/dl-lookupcfg.h: Inlcude dl-fptr.h.
(DL_FIXUP_VALUE_TYPE, DL_FIXUP_MAKE_VALUE, DL_FIXUP_VALUE_CODE_ADDR,
DL_FIXUP_VALUE_ADD, DL_FIXUP_ADDR_VALUE): Define.
* sysdeps/hppa/sysdep.h: Use "!" as a separator. Cleanup comments.
* sysdeps/hppa/bits/link.h (La_hppa_regs, La_hppa_retval): Define.
Define prototypes for la_hppa_gnu_pltenter and la_hppa_gnu_pltexit.
2006-05-14 23:54:47 +00:00
|
|
|
if (sym != NULL)
|
2018-04-21 03:11:29 +00:00
|
|
|
*reloc_addr = sym->st_value + reloc->r_addend;
|
2006-05-15 Carlos O'Donell <carlos@systemhalted.org>
* sysdeps/hppa/dl-machine.h: Include tls.h
(elf_machine_fixup_plt): Returns fdesc.
(elf_machine_profile_fixup_plt): Remove.
(elf_machine_plt_value): Returns fdesc.
(elf_machine_runtime_setup): Check that dl_profile != NULL.
(ARCH_LA_PLTENT, ARCH_LA_PLTEXIT): Define.
(RTLD_START): Use iitlbp with sr0.
(elf_machine_type_class): Include TLS relocs.
(reassemble_21, reassemble_14): Define.
(elf_machine_rela): Add DIR21L, DIR14R, PLABEL21L, PLABEL14R,
TLS_DTPMOD32, TLS_TPREL32, TLS_DTPOFF32 support.
(TRAMPOLINE_TEMPLATE): Move to ...
* sysdeps/hppa/dl-trampoline.S: ... here.
* sysdeps/hppa/abort-instr.h: Use iitlbp with sr0.
* sysdeps/hppa/dl-lookupcfg.h: Inlcude dl-fptr.h.
(DL_FIXUP_VALUE_TYPE, DL_FIXUP_MAKE_VALUE, DL_FIXUP_VALUE_CODE_ADDR,
DL_FIXUP_VALUE_ADD, DL_FIXUP_ADDR_VALUE): Define.
* sysdeps/hppa/sysdep.h: Use "!" as a separator. Cleanup comments.
* sysdeps/hppa/bits/link.h (La_hppa_regs, La_hppa_retval): Define.
Define prototypes for la_hppa_gnu_pltenter and la_hppa_gnu_pltexit.
2006-05-14 23:54:47 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
case R_PARISC_TLS_TPREL32:
|
|
|
|
/* The offset is negative, forward from the thread pointer */
|
|
|
|
if (sym != NULL)
|
2011-10-05 09:52:45 +00:00
|
|
|
{
|
|
|
|
CHECK_STATIC_TLS (map, sym_map);
|
2006-05-15 Carlos O'Donell <carlos@systemhalted.org>
* sysdeps/hppa/dl-machine.h: Include tls.h
(elf_machine_fixup_plt): Returns fdesc.
(elf_machine_profile_fixup_plt): Remove.
(elf_machine_plt_value): Returns fdesc.
(elf_machine_runtime_setup): Check that dl_profile != NULL.
(ARCH_LA_PLTENT, ARCH_LA_PLTEXIT): Define.
(RTLD_START): Use iitlbp with sr0.
(elf_machine_type_class): Include TLS relocs.
(reassemble_21, reassemble_14): Define.
(elf_machine_rela): Add DIR21L, DIR14R, PLABEL21L, PLABEL14R,
TLS_DTPMOD32, TLS_TPREL32, TLS_DTPOFF32 support.
(TRAMPOLINE_TEMPLATE): Move to ...
* sysdeps/hppa/dl-trampoline.S: ... here.
* sysdeps/hppa/abort-instr.h: Use iitlbp with sr0.
* sysdeps/hppa/dl-lookupcfg.h: Inlcude dl-fptr.h.
(DL_FIXUP_VALUE_TYPE, DL_FIXUP_MAKE_VALUE, DL_FIXUP_VALUE_CODE_ADDR,
DL_FIXUP_VALUE_ADD, DL_FIXUP_ADDR_VALUE): Define.
* sysdeps/hppa/sysdep.h: Use "!" as a separator. Cleanup comments.
* sysdeps/hppa/bits/link.h (La_hppa_regs, La_hppa_retval): Define.
Define prototypes for la_hppa_gnu_pltenter and la_hppa_gnu_pltexit.
2006-05-14 23:54:47 +00:00
|
|
|
value = sym_map->l_tls_offset + sym->st_value + reloc->r_addend;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif /* use TLS */
|
2011-10-05 09:52:45 +00:00
|
|
|
|
2000-10-15 03:20:01 +00:00
|
|
|
case R_PARISC_NONE: /* Alright, Wilbur. */
|
|
|
|
return;
|
|
|
|
|
|
|
|
default:
|
|
|
|
_dl_reloc_bad_type (map, r_type, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
*reloc_addr = value;
|
|
|
|
}
|
|
|
|
|
2002-09-28 04:34:00 +00:00
|
|
|
/* hppa doesn't have an R_PARISC_RELATIVE reloc, but uses relocs with
|
|
|
|
ELF32_R_SYM (info) == 0 for a similar purpose. */
|
elf: Avoid nested functions in the loader [BZ #27220]
dynamic-link.h is included more than once in some elf/ files (rtld.c,
dl-conflict.c, dl-reloc.c, dl-reloc-static-pie.c) and uses GCC nested
functions. This harms readability and the nested functions usage
is the biggest obstacle prevents Clang build (Clang doesn't support GCC
nested functions).
The key idea for unnesting is to add extra parameters (struct link_map
*and struct r_scope_elm *[]) to RESOLVE_MAP,
ELF_MACHINE_BEFORE_RTLD_RELOC, ELF_DYNAMIC_RELOCATE, elf_machine_rel[a],
elf_machine_lazy_rel, and elf_machine_runtime_setup. (This is inspired
by Stan Shebs' ppc64/x86-64 implementation in the
google/grte/v5-2.27/master which uses mixed extra parameters and static
variables.)
Future simplification:
* If mips elf_machine_runtime_setup no longer needs RESOLVE_GOTSYM,
elf_machine_runtime_setup can drop the `scope` parameter.
* If TLSDESC no longer need to be in elf_machine_lazy_rel,
elf_machine_lazy_rel can drop the `scope` parameter.
Tested on aarch64, i386, x86-64, powerpc64le, powerpc64, powerpc32,
sparc64, sparcv9, s390x, s390, hppa, ia64, armhf, alpha, and mips64.
In addition, tested build-many-glibcs.py with {arc,csky,microblaze,nios2}-linux-gnu
and riscv64-linux-gnu-rv64imafdc-lp64d.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-10-07 18:55:02 +00:00
|
|
|
static void __attribute__((always_inline))
|
2004-04-17 22:53:29 +00:00
|
|
|
elf_machine_rela_relative (Elf32_Addr l_addr,
|
2002-09-28 04:34:00 +00:00
|
|
|
const Elf32_Rela *reloc,
|
* elf/dynamic-link.h (elf_machine_rel, elf_machine_rela,
elf_machine_rel_relative, elf_machine_rela_relative): Don't assume
reloc_addr is aligned.
* sysdeps/alpha/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/arm/dl-machine.h (elf_machine_rel, elf_machine_rela,
elf_machine_rel_relative, elf_machine_rela_relative): Adjust.
* sysdeps/cris/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/hppa/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/i386/dl-machine.h (elf_machine_rel, elf_machine_rela,
elf_machine_rel_relative, elf_machine_rela_relative): Adjust.
* sysdeps/ia64/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/m68k/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/mips/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/powerpc/powerpc32/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/powerpc/powerpc64/dl-machine.h
(elf_machine_rela_relative, elf_machine_rela): Adjust.
* sysdeps/s390/s390-32/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/s390/s390-64/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative):
* sysdeps/sh/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/sparc/sparc32/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/sparc/sparc64/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/x86_64/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
2003-07-31 06:33:52 +00:00
|
|
|
void *const reloc_addr_arg)
|
2001-08-24 08:43:21 +00:00
|
|
|
{
|
2002-09-28 04:34:00 +00:00
|
|
|
unsigned long const r_type = ELF32_R_TYPE (reloc->r_info);
|
2004-04-17 22:53:29 +00:00
|
|
|
Elf32_Addr *const reloc_addr = reloc_addr_arg;
|
2011-10-05 09:52:45 +00:00
|
|
|
static char msgbuf[] = { "Unknown" };
|
2004-04-17 22:53:29 +00:00
|
|
|
struct link_map map;
|
2002-09-28 04:34:00 +00:00
|
|
|
Elf32_Addr value;
|
|
|
|
|
|
|
|
value = l_addr + reloc->r_addend;
|
|
|
|
|
2011-10-05 09:52:45 +00:00
|
|
|
if (ELF32_R_SYM (reloc->r_info) != 0){
|
2004-04-17 22:53:29 +00:00
|
|
|
_dl_error_printf ("%s: In elf_machine_rela_relative "
|
|
|
|
"ELF32_R_SYM (reloc->r_info) != 0. Aborting.",
|
2013-05-29 16:00:20 +00:00
|
|
|
RTLD_PROGNAME);
|
2004-04-17 22:53:29 +00:00
|
|
|
ABORT_INSTRUCTION; /* Crash. */
|
|
|
|
}
|
2002-09-28 04:34:00 +00:00
|
|
|
|
|
|
|
switch (r_type)
|
|
|
|
{
|
|
|
|
case R_PARISC_DIR32:
|
|
|
|
/* .eh_frame can have unaligned relocs. */
|
* elf/dynamic-link.h (elf_machine_rel, elf_machine_rela,
elf_machine_rel_relative, elf_machine_rela_relative): Don't assume
reloc_addr is aligned.
* sysdeps/alpha/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/arm/dl-machine.h (elf_machine_rel, elf_machine_rela,
elf_machine_rel_relative, elf_machine_rela_relative): Adjust.
* sysdeps/cris/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/hppa/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/i386/dl-machine.h (elf_machine_rel, elf_machine_rela,
elf_machine_rel_relative, elf_machine_rela_relative): Adjust.
* sysdeps/ia64/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/m68k/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/mips/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/powerpc/powerpc32/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/powerpc/powerpc64/dl-machine.h
(elf_machine_rela_relative, elf_machine_rela): Adjust.
* sysdeps/s390/s390-32/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/s390/s390-64/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative):
* sysdeps/sh/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/sparc/sparc32/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/sparc/sparc64/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/x86_64/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
2003-07-31 06:33:52 +00:00
|
|
|
if ((unsigned long) reloc_addr_arg & 3)
|
2002-09-28 04:34:00 +00:00
|
|
|
{
|
* elf/dynamic-link.h (elf_machine_rel, elf_machine_rela,
elf_machine_rel_relative, elf_machine_rela_relative): Don't assume
reloc_addr is aligned.
* sysdeps/alpha/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/arm/dl-machine.h (elf_machine_rel, elf_machine_rela,
elf_machine_rel_relative, elf_machine_rela_relative): Adjust.
* sysdeps/cris/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/hppa/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/i386/dl-machine.h (elf_machine_rel, elf_machine_rela,
elf_machine_rel_relative, elf_machine_rela_relative): Adjust.
* sysdeps/ia64/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/m68k/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/mips/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/powerpc/powerpc32/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/powerpc/powerpc64/dl-machine.h
(elf_machine_rela_relative, elf_machine_rela): Adjust.
* sysdeps/s390/s390-32/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/s390/s390-64/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative):
* sysdeps/sh/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/sparc/sparc32/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/sparc/sparc64/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
* sysdeps/x86_64/dl-machine.h (elf_machine_rela,
elf_machine_rela_relative): Adjust.
2003-07-31 06:33:52 +00:00
|
|
|
char *rel_addr = (char *) reloc_addr_arg;
|
2002-09-28 04:34:00 +00:00
|
|
|
rel_addr[0] = value >> 24;
|
|
|
|
rel_addr[1] = value >> 16;
|
|
|
|
rel_addr[2] = value >> 8;
|
|
|
|
rel_addr[3] = value;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case R_PARISC_PLABEL32:
|
|
|
|
break;
|
|
|
|
|
2004-04-17 22:53:29 +00:00
|
|
|
case R_PARISC_IPLT: /* elf_machine_runtime_setup already set gp */
|
|
|
|
break;
|
2002-09-28 04:34:00 +00:00
|
|
|
|
|
|
|
case R_PARISC_NONE:
|
|
|
|
return;
|
|
|
|
|
2004-04-17 22:53:29 +00:00
|
|
|
default: /* Bad reloc, map unknown (really it's the current map) */
|
|
|
|
map.l_name = msgbuf;
|
|
|
|
_dl_reloc_bad_type (&map, r_type, 0);
|
|
|
|
return;
|
2002-09-28 04:34:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*reloc_addr = value;
|
2001-08-24 08:43:21 +00:00
|
|
|
}
|
|
|
|
|
elf: Avoid nested functions in the loader [BZ #27220]
dynamic-link.h is included more than once in some elf/ files (rtld.c,
dl-conflict.c, dl-reloc.c, dl-reloc-static-pie.c) and uses GCC nested
functions. This harms readability and the nested functions usage
is the biggest obstacle prevents Clang build (Clang doesn't support GCC
nested functions).
The key idea for unnesting is to add extra parameters (struct link_map
*and struct r_scope_elm *[]) to RESOLVE_MAP,
ELF_MACHINE_BEFORE_RTLD_RELOC, ELF_DYNAMIC_RELOCATE, elf_machine_rel[a],
elf_machine_lazy_rel, and elf_machine_runtime_setup. (This is inspired
by Stan Shebs' ppc64/x86-64 implementation in the
google/grte/v5-2.27/master which uses mixed extra parameters and static
variables.)
Future simplification:
* If mips elf_machine_runtime_setup no longer needs RESOLVE_GOTSYM,
elf_machine_runtime_setup can drop the `scope` parameter.
* If TLSDESC no longer need to be in elf_machine_lazy_rel,
elf_machine_lazy_rel can drop the `scope` parameter.
Tested on aarch64, i386, x86-64, powerpc64le, powerpc64, powerpc32,
sparc64, sparcv9, s390x, s390, hppa, ia64, armhf, alpha, and mips64.
In addition, tested build-many-glibcs.py with {arc,csky,microblaze,nios2}-linux-gnu
and riscv64-linux-gnu-rv64imafdc-lp64d.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-10-07 18:55:02 +00:00
|
|
|
static void __attribute__((always_inline))
|
|
|
|
elf_machine_lazy_rel (struct link_map *map, struct r_scope_elem *scope[],
|
2011-10-05 09:52:45 +00:00
|
|
|
Elf32_Addr l_addr, const Elf32_Rela *reloc,
|
|
|
|
int skip_ifunc)
|
2000-10-15 03:20:01 +00:00
|
|
|
{
|
|
|
|
/* We don't have anything to do here. elf_machine_runtime_setup has
|
|
|
|
done all the relocs already. */
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* RESOLVE_MAP */
|