Deleted Added
full compact
reloc.c (45501) reloc.c (48205)
1/*-
1/*-
2 * Copyright 1996-1998 John D. Polstra.
2 * Copyright 1996, 1997, 1998, 1999 John D. Polstra.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright

--- 6 unchanged lines hidden (view full) ---

17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 *
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright

--- 6 unchanged lines hidden (view full) ---

17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 *
25 * $Id: reloc.c,v 1.1 1998/09/04 19:03:57 dfr Exp $
25 * $Id: reloc.c,v 1.2 1999/04/09 00:28:43 jdp Exp $
26 */
27
28/*
29 * Dynamic linker for ELF.
30 *
31 * John Polstra <jdp@polstra.com>.
32 */
33

--- 175 unchanged lines hidden (view full) ---

209 }
210 return 0;
211}
212
213/* Process the PLT relocations. */
214int
215reloc_plt(Obj_Entry *obj, bool bind_now)
216{
26 */
27
28/*
29 * Dynamic linker for ELF.
30 *
31 * John Polstra <jdp@polstra.com>.
32 */
33

--- 175 unchanged lines hidden (view full) ---

209 }
210 return 0;
211}
212
213/* Process the PLT relocations. */
214int
215reloc_plt(Obj_Entry *obj, bool bind_now)
216{
217 const Elf_Rel *rellim;
218 const Elf_Rel *rel;
217 const Elf_Rel *rellim;
218 const Elf_Rel *rel;
219
219
220 /* Process the PLT relocations. */
221 rellim = (const Elf_Rel *) ((caddr_t) obj->pltrel + obj->pltrelsize);
222 if (bind_now) {
223 /* Fully resolve procedure addresses now */
224 for (rel = obj->pltrel; rel < rellim; rel++) {
225 Elf_Addr *where = (Elf_Addr *)
226 (obj->relocbase + rel->r_offset);
227 const Elf_Sym *def;
228 const Obj_Entry *defobj;
220 rellim = (const Elf_Rel *)((char *)obj->pltrel + obj->pltrelsize);
221 for (rel = obj->pltrel; rel < rellim; rel++) {
222 Elf_Addr *where;
229
223
230 assert(ELF_R_TYPE(rel->r_info) == R_386_JMP_SLOT);
224 assert(ELF_R_TYPE(rel->r_info) == R_386_JMP_SLOT);
231
225
232 def = find_symdef(ELF_R_SYM(rel->r_info), obj, &defobj, true);
233 if (def == NULL)
234 return -1;
226 /* Relocate the GOT slot pointing into the PLT. */
227 where = (Elf_Addr *)(obj->relocbase + rel->r_offset);
228 *where += (Elf_Addr)obj->relocbase;
235
229
236 *where = (Elf_Addr) (defobj->relocbase + def->st_value);
237 }
238 } else { /* Just relocate the GOT slots pointing into the PLT */
239 for (rel = obj->pltrel; rel < rellim; rel++) {
240 Elf_Addr *where = (Elf_Addr *)
241 (obj->relocbase + rel->r_offset);
242 *where += (Elf_Addr) obj->relocbase;
243 }
230 if (bind_now) { /* Fully resolve the procedure address. */
231 const Elf_Sym *def;
232 const Obj_Entry *defobj;
233
234 def = find_symdef(ELF_R_SYM(rel->r_info), obj, &defobj, true);
235 if (def == NULL)
236 return -1;
237 reloc_jmpslot(where,
238 (Elf_Addr)(defobj->relocbase + def->st_value));
244 }
239 }
240 }
245 return 0;
246}
241 return 0;
242}