1 /* On-demand PLT fixup for shared objects.  HPPA version.
2    Copyright (C) 2019-2022 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4 
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
9 
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
14 
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, write to the Free
17    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18    02111-1307 USA.  */
19 
20 #include <elf/dl-runtime.c>
21 
22 /* The caller has encountered a partially relocated function descriptor.
23    The gp of the descriptor has been updated, but not the ip.  We find
24    the function descriptor again and compute the relocation offset and
25    return that to the caller.  The caller will continue on to call
26    _dl_fixup with the relocation offset.  */
27 
28 ElfW(Word) __attribute ((noinline)) DL_ARCH_FIXUP_ATTRIBUTE
_dl_fix_reloc_arg(struct fdesc * fptr,struct link_map * l)29 _dl_fix_reloc_arg (struct fdesc *fptr, struct link_map *l)
30 {
31   Elf32_Addr l_addr, iplt, jmprel, end_jmprel, r_type;
32   const Elf32_Rela *reloc;
33 
34   l_addr = l->l_addr;
35   jmprel = D_PTR(l, l_info[DT_JMPREL]);
36   end_jmprel = jmprel + l->l_info[DT_PLTRELSZ]->d_un.d_val;
37 
38   /* Look for the entry...  */
39   for (iplt = jmprel; iplt < end_jmprel; iplt += sizeof (Elf32_Rela))
40     {
41       reloc = (const Elf32_Rela *) iplt;
42       r_type = ELF32_R_TYPE (reloc->r_info);
43 
44       if (__builtin_expect (r_type == R_PARISC_IPLT, 1)
45 	  && fptr == (struct fdesc *) (reloc->r_offset + l_addr))
46 	/* Found entry. Return the reloc offset.  */
47 	return iplt - jmprel;
48     }
49 
50   /* Crash if we weren't passed a valid function pointer.  */
51   ABORT_INSTRUCTION;
52   return 0;
53 }
54 rtld_hidden_def (_dl_fix_reloc_arg)
55