]>
Commit | Line | Data |
---|---|---|
421f82e5 RM |
1 | /* Do relocations for ELF dynamic linking. |
2 | Copyright (C) 1995 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 | |
17 | not, write to the Free Software Foundation, Inc., 675 Mass Ave, | |
18 | Cambridge, MA 02139, 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 Elf32_Rel Elf32_Rela | |
26 | #define elf_machine_rel elf_machine_rela | |
27 | #endif | |
28 | ||
29 | ||
30 | /* Perform the relocations in MAP on the running program image as specified | |
31 | by RELTAG, SZTAG. *RESOLVE is called to resolve symbol values; it | |
32 | modifies its argument pointer to point to the defining symbol, and | |
a1a9d215 RM |
33 | returns the base load address of the defining object. If LAZY is |
34 | nonzero, this is the first pass on PLT relocations; they should be set | |
35 | up to call _dl_runtime_resolve, rather than fully resolved now. */ | |
421f82e5 RM |
36 | |
37 | static inline void | |
38 | elf_dynamic_do_rel (struct link_map *map, | |
39 | int reltag, int sztag, | |
a1a9d215 RM |
40 | Elf32_Addr (*resolve) (const Elf32_Sym **), |
41 | int lazy) | |
421f82e5 RM |
42 | { |
43 | const Elf32_Sym *const symtab | |
a1a9d215 RM |
44 | = (const Elf32_Sym *) (map->l_addr + map->l_info[DT_SYMTAB]->d_un.d_ptr); |
45 | const Elf32_Rel *r | |
46 | = (const Elf32_Rel *) (map->l_addr + map->l_info[reltag]->d_un.d_ptr); | |
421f82e5 RM |
47 | const Elf32_Rel *end = &r[map->l_info[sztag]->d_un.d_val / sizeof *r]; |
48 | ||
a1a9d215 RM |
49 | if (lazy) |
50 | /* Doing lazy PLT relocations; they need very little info. */ | |
51 | for (; r < end; ++r) | |
52 | elf_machine_lazy_rel (map, r); | |
53 | else | |
54 | for (; r < end; ++r) | |
55 | { | |
56 | const Elf32_Sym *definer = &symtab[ELF32_R_SYM (r->r_info)]; | |
57 | Elf32_Addr loadbase; | |
421f82e5 | 58 | |
a1a9d215 RM |
59 | if (ELF32_R_SYM (r->r_info) == STN_UNDEF) |
60 | loadbase = 0; /* This value will not be consulted. */ | |
61 | else | |
62 | { | |
63 | if (resolve) | |
64 | loadbase = (*resolve) (&definer); | |
65 | else | |
66 | { | |
67 | assert (definer->st_shndx != SHN_UNDEF); | |
68 | loadbase = map->l_addr; | |
69 | } | |
70 | } | |
71 | elf_machine_rel (map, r, loadbase, definer); | |
72 | } | |
421f82e5 RM |
73 | } |
74 | ||
75 | #undef elf_dynamic_do_rel | |
76 | #undef Elf32_Rel | |
77 | #undef elf_machine_rel |