Update.
[platform/upstream/glibc.git] / elf / do-rel.h
1 /* Do relocations for ELF dynamic linking.
2    Copyright (C) 1995,96,97,98,99,2000 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 Library General Public License as
7    published by the Free Software Foundation; either version 2 of the
8    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    Library General Public License for more details.
14
15    You should have received a copy of the GNU Library General Public
16    License along with the GNU C Library; see the file COPYING.LIB.  If not,
17    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18    Boston, MA 02111-1307, USA.  */
19
20 /* This file may be included twice, to define both
21    `elf_dynamic_do_rel' and `elf_dynamic_do_rela'.  */
22
23 #ifdef DO_RELA
24 # define elf_dynamic_do_rel     elf_dynamic_do_rela
25 # define Rel                    Rela
26 # define elf_machine_rel        elf_machine_rela
27 #endif
28
29 #ifndef VERSYMIDX
30 # define VERSYMIDX(sym) (DT_NUM + DT_THISPROCNUM + DT_VERSIONTAGIDX (sym))
31 #endif
32
33 /* Perform the relocations in MAP on the running program image as specified
34    by RELTAG, SZTAG.  If LAZY is nonzero, this is the first pass on PLT
35    relocations; they should be set up to call _dl_runtime_resolve, rather
36    than fully resolved now.  */
37
38 static inline void
39 elf_dynamic_do_rel (struct link_map *map,
40                     ElfW(Addr) reladdr, ElfW(Addr) relsize,
41                     int lazy)
42 {
43   const ElfW(Rel) *r = (const void *) reladdr;
44   const ElfW(Rel) *end = (const void *) (reladdr + relsize);
45
46   if (lazy)
47     {
48       /* Doing lazy PLT relocations; they need very little info.  */
49       ElfW(Addr) l_addr = map->l_addr;
50       for (; r < end; ++r)
51         elf_machine_lazy_rel (map, l_addr, r);
52     }
53   else
54     {
55       const ElfW(Sym) *const symtab =
56         (const void *) D_PTR (map, l_info[DT_SYMTAB]);
57
58       if (map->l_info[VERSYMIDX (DT_VERSYM)])
59         {
60           const ElfW(Half) *const version =
61             (const void *) D_PTR (map, l_info[VERSYMIDX (DT_VERSYM)]);
62
63           for (; r < end; ++r)
64             {
65               ElfW(Half) ndx = version[ELFW(R_SYM) (r->r_info)];
66               elf_machine_rel (map, r, &symtab[ELFW(R_SYM) (r->r_info)],
67                                &map->l_versions[ndx],
68                                (void *) (map->l_addr + r->r_offset));
69             }
70         }
71       else
72         for (; r < end; ++r)
73           elf_machine_rel (map, r, &symtab[ELFW(R_SYM) (r->r_info)], NULL,
74                            (void *) (map->l_addr + r->r_offset));
75     }
76 }
77
78 #undef elf_dynamic_do_rel
79 #undef Rel
80 #undef elf_machine_rel