hppa_reloc.c revision 1.12 1 1.12 mycroft /* $NetBSD: hppa_reloc.c,v 1.12 2002/09/12 20:20:59 mycroft Exp $ */
2 1.1 fredette
3 1.1 fredette /*-
4 1.1 fredette * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 1.1 fredette * All rights reserved.
6 1.1 fredette *
7 1.1 fredette * This code is derived from software contributed to The NetBSD Foundation
8 1.1 fredette * by Matt Fredette.
9 1.1 fredette *
10 1.1 fredette * Redistribution and use in source and binary forms, with or without
11 1.1 fredette * modification, are permitted provided that the following conditions
12 1.1 fredette * are met:
13 1.1 fredette * 1. Redistributions of source code must retain the above copyright
14 1.1 fredette * notice, this list of conditions and the following disclaimer.
15 1.1 fredette * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 fredette * notice, this list of conditions and the following disclaimer in the
17 1.1 fredette * documentation and/or other materials provided with the distribution.
18 1.1 fredette * 3. All advertising materials mentioning features or use of this software
19 1.1 fredette * must display the following acknowledgement:
20 1.1 fredette * This product includes software developed by the NetBSD
21 1.1 fredette * Foundation, Inc. and its contributors.
22 1.1 fredette * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 fredette * contributors may be used to endorse or promote products derived
24 1.1 fredette * from this software without specific prior written permission.
25 1.1 fredette *
26 1.1 fredette * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 fredette * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 fredette * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 fredette * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 fredette * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 fredette * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 fredette * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 fredette * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 fredette * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 fredette * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 fredette * POSSIBILITY OF SUCH DAMAGE.
37 1.1 fredette */
38 1.1 fredette
39 1.1 fredette #include <stdlib.h>
40 1.1 fredette #include <sys/types.h>
41 1.1 fredette #include <sys/stat.h>
42 1.1 fredette #include <sys/queue.h>
43 1.1 fredette
44 1.1 fredette #include "rtld.h"
45 1.1 fredette #include "debug.h"
46 1.1 fredette
47 1.1 fredette #ifdef RTLD_DEBUG_HPPA
48 1.1 fredette #define hdbg(x) if (dodebug) xprintf x
49 1.1 fredette #else
50 1.1 fredette #define hdbg(x) /* nothing */
51 1.1 fredette #endif
52 1.12 mycroft
53 1.12 mycroft void _rtld_bind_start(void);
54 1.1 fredette
55 1.1 fredette /*
56 1.1 fredette * In the runtime architecture (ABI), PLABEL function
57 1.1 fredette * pointers are distinguished from normal function
58 1.1 fredette * pointers by having the next-least-significant bit
59 1.1 fredette * set. (This bit is referred to as the L field in
60 1.1 fredette * HP documentation). The $$dyncall millicode is
61 1.1 fredette * aware of this.
62 1.1 fredette */
63 1.1 fredette #define RTLD_MAKE_PLABEL(plabel) (((Elf_Addr)(plabel)) | (1 << 1))
64 1.1 fredette #define RTLD_IS_PLABEL(addr) (((Elf_Addr)(addr)) & (1 << 1))
65 1.1 fredette #define RTLD_GET_PLABEL(addr) ((hppa_plabel *) (((Elf_Addr)addr) & ~3))
66 1.1 fredette
67 1.1 fredette /*
68 1.1 fredette * This is the PLABEL structure. The function PC and
69 1.1 fredette * shared linkage members must come first, as they are
70 1.1 fredette * the actual PLABEL.
71 1.1 fredette */
72 1.1 fredette typedef struct _hppa_plabel {
73 1.1 fredette Elf_Addr hppa_plabel_pc;
74 1.1 fredette Elf_Addr hppa_plabel_sl;
75 1.1 fredette SLIST_ENTRY(_hppa_plabel) hppa_plabel_next;
76 1.1 fredette } hppa_plabel;
77 1.1 fredette
78 1.1 fredette /*
79 1.1 fredette * For now allocated PLABEL structures are tracked on a
80 1.1 fredette * singly linked list. This maybe should be revisited.
81 1.1 fredette */
82 1.1 fredette static SLIST_HEAD(hppa_plabel_head, _hppa_plabel) hppa_plabel_list
83 1.1 fredette = SLIST_HEAD_INITIALIZER(hppa_plabel_list);
84 1.1 fredette
85 1.1 fredette /*
86 1.1 fredette * Because I'm hesitant to use NEW while relocating self,
87 1.1 fredette * this is a small pool of preallocated PLABELs.
88 1.1 fredette */
89 1.1 fredette #define HPPA_PLABEL_PRE (10)
90 1.1 fredette static hppa_plabel hppa_plabel_pre[HPPA_PLABEL_PRE];
91 1.1 fredette static int hppa_plabel_pre_next = 0;
92 1.1 fredette
93 1.1 fredette /*
94 1.1 fredette * The DT_PLTGOT _DYNAMIC entry always gives the linkage table
95 1.1 fredette * pointer for an object. This is often, but not always, the
96 1.1 fredette * same as the object's value for _GLOBAL_OFFSET_TABLE_. We
97 1.1 fredette * cache one object's GOT value, otherwise we look it up.
98 1.1 fredette * XXX it would be nice to be able to keep this in the Obj_Entry.
99 1.1 fredette */
100 1.1 fredette static const Obj_Entry *hppa_got_cache_obj = NULL;
101 1.1 fredette static Elf_Addr *hppa_got_cache_got;
102 1.1 fredette #define HPPA_OBJ_SL(obj) ((obj)->pltgot)
103 1.1 fredette #define HPPA_OBJ_GOT(obj) ((obj) == hppa_got_cache_obj ? \
104 1.1 fredette hppa_got_cache_got : \
105 1.1 fredette _rtld_fill_hppa_got_cache(obj))
106 1.1 fredette static Elf_Addr *_rtld_fill_hppa_got_cache __P((const Obj_Entry *));
107 1.1 fredette
108 1.1 fredette /*
109 1.1 fredette * This bootstraps the dynamic linker by relocating its GOT.
110 1.1 fredette * On the hppa, unlike on other architectures, static strings
111 1.1 fredette * are found through the GOT. Static strings are essential
112 1.1 fredette * for RTLD_DEBUG, and I suspect they're used early even when
113 1.1 fredette * !defined(RTLD_DEBUG), making relocating the GOT essential.
114 1.1 fredette *
115 1.1 fredette * It gets worse. Relocating the GOT doesn't mean just walking
116 1.1 fredette * it and adding the relocbase to all of the entries. You must
117 1.1 fredette * find and use the GOT relocations, since those RELA relocations
118 1.1 fredette * have the necessary addends - the GOT comes initialized as
119 1.1 fredette * zeroes.
120 1.1 fredette */
121 1.1 fredette void
122 1.1 fredette _rtld_bootstrap_hppa_got(Elf_Dyn *dynp, Elf_Addr relocbase,
123 1.1 fredette Elf_Addr got_begin, Elf_Addr got_end)
124 1.1 fredette {
125 1.1 fredette const Elf_Rela *relafirst, *rela, *relalim;
126 1.1 fredette Elf_Addr relasz = 0;
127 1.1 fredette Elf_Addr where;
128 1.1 fredette
129 1.1 fredette /*
130 1.1 fredette * Process the DYNAMIC section, looking for the non-PLT
131 1.1 fredette * relocations.
132 1.1 fredette */
133 1.1 fredette relafirst = NULL;
134 1.1 fredette for (; dynp->d_tag != DT_NULL; ++dynp) {
135 1.1 fredette switch (dynp->d_tag) {
136 1.1 fredette
137 1.1 fredette case DT_RELA:
138 1.1 fredette relafirst = (const Elf_Rela *)
139 1.1 fredette (relocbase + dynp->d_un.d_ptr);
140 1.1 fredette break;
141 1.1 fredette
142 1.1 fredette case DT_RELASZ:
143 1.1 fredette relasz = dynp->d_un.d_val;
144 1.1 fredette break;
145 1.1 fredette }
146 1.1 fredette }
147 1.1 fredette relalim = (const Elf_Rela *)((caddr_t)relafirst + relasz);
148 1.1 fredette
149 1.1 fredette /*
150 1.1 fredette * Process all relocations that look like they're in
151 1.1 fredette * the GOT.
152 1.1 fredette */
153 1.1 fredette for(rela = relafirst; rela < relalim; rela++) {
154 1.1 fredette where = (Elf_Addr)(relocbase + rela->r_offset);
155 1.1 fredette if (where >= got_begin && where < got_end)
156 1.1 fredette *((Elf_Addr *)where) = relocbase + rela->r_addend;
157 1.1 fredette }
158 1.1 fredette
159 1.1 fredette #if defined(RTLD_DEBUG_HPPA)
160 1.1 fredette for(rela = relafirst; rela < relalim; rela++) {
161 1.1 fredette where = (Elf_Addr)(relocbase + rela->r_offset);
162 1.1 fredette if (where >= got_begin && where < got_end)
163 1.1 fredette xprintf("GOT rela @%p(%p) -> %p(%p)\n",
164 1.1 fredette (void *)rela->r_offset,
165 1.1 fredette (void *)where,
166 1.1 fredette (void *)rela->r_addend,
167 1.1 fredette (void *)*((Elf_Addr *)where));
168 1.1 fredette }
169 1.1 fredette #endif /* RTLD_DEBUG_HPPA */
170 1.1 fredette }
171 1.1 fredette
172 1.1 fredette /*
173 1.1 fredette * This looks up the object's _GLOBAL_OFFSET_TABLE_
174 1.1 fredette * and caches the result.
175 1.1 fredette */
176 1.1 fredette static Elf_Addr *
177 1.1 fredette _rtld_fill_hppa_got_cache(const Obj_Entry *obj)
178 1.1 fredette {
179 1.1 fredette const char *name = "_GLOBAL_OFFSET_TABLE_";
180 1.1 fredette unsigned long hash;
181 1.1 fredette const Elf_Sym *def;
182 1.1 fredette
183 1.1 fredette hash = _rtld_elf_hash(name);
184 1.1 fredette def = _rtld_symlook_obj(name, hash, obj, true);
185 1.1 fredette assert(def != NULL);
186 1.1 fredette hppa_got_cache_obj = obj;
187 1.1 fredette return hppa_got_cache_got =
188 1.1 fredette (Elf_Addr *)(obj->relocbase + def->st_value);
189 1.1 fredette }
190 1.1 fredette
191 1.1 fredette /*
192 1.1 fredette * This allocates a PLABEL. If called with a non-NULL def, the
193 1.1 fredette * plabel is for the function associated with that definition
194 1.1 fredette * in the defining object defobj, plus the given addend. If
195 1.1 fredette * called with a NULL def, the plabel is for the function at
196 1.1 fredette * the (unrelocated) address in addend in the object defobj.
197 1.1 fredette */
198 1.1 fredette Elf_Addr
199 1.1 fredette _rtld_function_descriptor_alloc(const Obj_Entry *defobj, const Elf_Sym *def,
200 1.1 fredette Elf_Addr addend)
201 1.1 fredette {
202 1.1 fredette Elf_Addr func_pc, func_sl;
203 1.1 fredette hppa_plabel *plabel;
204 1.1 fredette
205 1.1 fredette if (def != NULL) {
206 1.1 fredette
207 1.1 fredette /*
208 1.1 fredette * We assume that symbols of type STT_NOTYPE
209 1.1 fredette * are undefined. Return NULL for these.
210 1.1 fredette */
211 1.1 fredette if (ELF_ST_TYPE(def->st_info) == STT_NOTYPE)
212 1.1 fredette return (Elf_Addr)NULL;
213 1.1 fredette
214 1.1 fredette /* Otherwise assert that this symbol must be a function. */
215 1.1 fredette assert(ELF_ST_TYPE(def->st_info) == STT_FUNC);
216 1.1 fredette
217 1.1 fredette func_pc = (Elf_Addr)(defobj->relocbase + def->st_value +
218 1.1 fredette addend);
219 1.1 fredette } else
220 1.1 fredette func_pc = (Elf_Addr)(defobj->relocbase + addend);
221 1.1 fredette
222 1.1 fredette /*
223 1.1 fredette * Search the existing PLABELs for one matching
224 1.1 fredette * this function. If there is one, return it.
225 1.1 fredette */
226 1.1 fredette func_sl = (Elf_Addr)HPPA_OBJ_SL(defobj);
227 1.1 fredette SLIST_FOREACH(plabel, &hppa_plabel_list, hppa_plabel_next)
228 1.1 fredette if (plabel->hppa_plabel_pc == func_pc &&
229 1.1 fredette plabel->hppa_plabel_sl == func_sl)
230 1.1 fredette return RTLD_MAKE_PLABEL(plabel);
231 1.1 fredette
232 1.1 fredette /*
233 1.1 fredette * XXX - this assumes that the dynamic linker doesn't
234 1.1 fredette * have more than HPPA_PLABEL_PRE PLABEL relocations.
235 1.1 fredette * Once we've used up the preallocated set, we start
236 1.1 fredette * using NEW to allocate plabels.
237 1.1 fredette */
238 1.1 fredette if (hppa_plabel_pre_next < HPPA_PLABEL_PRE)
239 1.1 fredette plabel = &hppa_plabel_pre[hppa_plabel_pre_next++];
240 1.1 fredette else {
241 1.1 fredette plabel = NEW(hppa_plabel);
242 1.1 fredette if (plabel == NULL)
243 1.1 fredette return (Elf_Addr)-1;
244 1.1 fredette }
245 1.1 fredette
246 1.1 fredette /* Fill the new entry and insert it on the list. */
247 1.1 fredette plabel->hppa_plabel_pc = func_pc;
248 1.1 fredette plabel->hppa_plabel_sl = func_sl;
249 1.1 fredette SLIST_INSERT_HEAD(&hppa_plabel_list, plabel, hppa_plabel_next);
250 1.1 fredette
251 1.1 fredette return RTLD_MAKE_PLABEL(plabel);
252 1.1 fredette }
253 1.1 fredette
254 1.1 fredette /*
255 1.1 fredette * If a pointer is a PLABEL, this unwraps it.
256 1.1 fredette */
257 1.1 fredette const void *
258 1.1 fredette _rtld_function_descriptor_function(const void *addr)
259 1.1 fredette {
260 1.1 fredette return (RTLD_IS_PLABEL(addr) ?
261 1.1 fredette (const void *) RTLD_GET_PLABEL(addr)->hppa_plabel_pc :
262 1.1 fredette addr);
263 1.1 fredette }
264 1.1 fredette
265 1.1 fredette /*
266 1.1 fredette * This handles an IPLT relocation, with or without a symbol.
267 1.1 fredette */
268 1.1 fredette int
269 1.9 mycroft _rtld_relocate_plt_object(const Obj_Entry *obj, const Elf_Rela *rela, caddr_t *addrp,
270 1.8 mycroft bool dodebug)
271 1.1 fredette {
272 1.1 fredette Elf_Addr *where = (Elf_Addr *)(obj->relocbase + rela->r_offset);
273 1.1 fredette const Elf_Sym *def;
274 1.1 fredette const Obj_Entry *defobj;
275 1.1 fredette Elf_Addr func_pc, func_sl;
276 1.1 fredette
277 1.1 fredette assert(ELF_R_TYPE(rela->r_info) == R_TYPE(IPLT));
278 1.1 fredette
279 1.1 fredette /*
280 1.1 fredette * If this is an IPLT reloc for a static function,
281 1.1 fredette * fully resolve the PLT entry now.
282 1.1 fredette */
283 1.1 fredette if (ELF_R_SYM(rela->r_info) == 0) {
284 1.1 fredette func_pc = (Elf_Addr)(obj->relocbase + rela->r_addend);
285 1.1 fredette func_sl = (Elf_Addr)HPPA_OBJ_SL(obj);
286 1.1 fredette }
287 1.1 fredette
288 1.1 fredette /*
289 1.1 fredette * If we must bind now, fully resolve the PLT entry.
290 1.1 fredette */
291 1.8 mycroft else {
292 1.1 fredette
293 1.1 fredette /*
294 1.1 fredette * Look up the symbol. While we're relocating self,
295 1.1 fredette * _rtld_objlist is NULL, so just pass in self.
296 1.1 fredette */
297 1.6 mycroft def = _rtld_find_symdef(ELF_R_SYM(rela->r_info), obj, &defobj,
298 1.6 mycroft false);
299 1.1 fredette if (def == NULL)
300 1.1 fredette return -1;
301 1.1 fredette func_pc = (Elf_Addr)(defobj->relocbase + def->st_value +
302 1.1 fredette rela->r_addend);
303 1.1 fredette func_sl = (Elf_Addr)HPPA_OBJ_SL(defobj);
304 1.1 fredette }
305 1.1 fredette
306 1.1 fredette /*
307 1.1 fredette * Fill this PLT entry and return.
308 1.1 fredette */
309 1.1 fredette where[0] = func_pc;
310 1.1 fredette where[1] = func_sl;
311 1.8 mycroft
312 1.8 mycroft *addrp = (caddr_t)where;
313 1.1 fredette return 0;
314 1.2 mycroft }
315 1.2 mycroft
316 1.2 mycroft /* This sets up an object's GOT. */
317 1.2 mycroft void
318 1.2 mycroft _rtld_setup_pltgot(const Obj_Entry *obj)
319 1.2 mycroft {
320 1.2 mycroft __rtld_setup_hppa_pltgot(obj, HPPA_OBJ_GOT(obj));
321 1.4 mycroft }
322 1.4 mycroft
323 1.4 mycroft int
324 1.11 mycroft _rtld_relocate_nonplt_objects(obj, self, dodebug)
325 1.9 mycroft const Obj_Entry *obj;
326 1.11 mycroft bool self;
327 1.4 mycroft bool dodebug;
328 1.4 mycroft {
329 1.5 mycroft const Elf_Rela *rela;
330 1.5 mycroft
331 1.5 mycroft for (rela = obj->rela; rela < obj->relalim; rela++) {
332 1.5 mycroft Elf_Addr *where;
333 1.5 mycroft const Elf_Sym *def;
334 1.5 mycroft const Obj_Entry *defobj;
335 1.5 mycroft Elf_Addr tmp;
336 1.6 mycroft unsigned long symnum;
337 1.5 mycroft
338 1.5 mycroft where = (Elf_Addr *)(obj->relocbase + rela->r_offset);
339 1.6 mycroft symnum = ELF_R_SYM(rela->r_info);
340 1.5 mycroft
341 1.5 mycroft switch (ELF_R_TYPE(rela->r_info)) {
342 1.5 mycroft case R_TYPE(NONE):
343 1.5 mycroft break;
344 1.4 mycroft
345 1.5 mycroft case R_TYPE(DIR32):
346 1.6 mycroft if (symnum) {
347 1.5 mycroft /*
348 1.5 mycroft * This is either a DIR32 against a symbol
349 1.5 mycroft * (def->st_name != 0), or against a local
350 1.5 mycroft * section (def->st_name == 0).
351 1.5 mycroft */
352 1.6 mycroft def = obj->symtab + symnum;
353 1.5 mycroft defobj = obj;
354 1.5 mycroft if (def->st_name != 0)
355 1.5 mycroft /*
356 1.5 mycroft * While we're relocating self,
357 1.5 mycroft * _rtld_objlist is NULL, so we just
358 1.5 mycroft * pass in self.
359 1.5 mycroft */
360 1.6 mycroft def = _rtld_find_symdef(symnum, obj,
361 1.6 mycroft &defobj, false);
362 1.5 mycroft if (def == NULL)
363 1.5 mycroft return -1;
364 1.4 mycroft
365 1.5 mycroft tmp = (Elf_Addr)(defobj->relocbase +
366 1.5 mycroft def->st_value + rela->r_addend);
367 1.4 mycroft
368 1.5 mycroft if (*where != tmp)
369 1.5 mycroft *where = tmp;
370 1.5 mycroft rdbg(dodebug, ("DIR32 %s in %s --> %p in %s",
371 1.7 mycroft obj->strtab + obj->symtab[symnum].st_name,
372 1.7 mycroft obj->path, (void *)*where, defobj->path));
373 1.5 mycroft } else {
374 1.5 mycroft extern Elf_Addr _GLOBAL_OFFSET_TABLE_[];
375 1.5 mycroft extern Elf_Addr _GOT_END_[];
376 1.5 mycroft
377 1.5 mycroft tmp = (Elf_Addr)(obj->relocbase +
378 1.5 mycroft rela->r_addend);
379 1.5 mycroft
380 1.5 mycroft /* This is the ...iffy hueristic. */
381 1.11 mycroft if (!self ||
382 1.5 mycroft (caddr_t)where < (caddr_t)_GLOBAL_OFFSET_TABLE_ ||
383 1.5 mycroft (caddr_t)where >= (caddr_t)_GOT_END_) {
384 1.5 mycroft if (*where != tmp)
385 1.5 mycroft *where = tmp;
386 1.5 mycroft rdbg(dodebug, ("DIR32 in %s --> %p",
387 1.5 mycroft obj->path, (void *)*where));
388 1.5 mycroft } else
389 1.5 mycroft rdbg(dodebug, ("DIR32 in %s stays at %p",
390 1.5 mycroft obj->path, (void *)*where));
391 1.5 mycroft }
392 1.5 mycroft break;
393 1.5 mycroft
394 1.5 mycroft case R_TYPE(PLABEL32):
395 1.6 mycroft if (symnum) {
396 1.4 mycroft /*
397 1.4 mycroft * While we're relocating self, _rtld_objlist
398 1.4 mycroft * is NULL, so we just pass in self.
399 1.4 mycroft */
400 1.6 mycroft def = _rtld_find_symdef(symnum, obj, &defobj,
401 1.6 mycroft false);
402 1.5 mycroft if (def == NULL)
403 1.5 mycroft return -1;
404 1.4 mycroft
405 1.5 mycroft tmp = _rtld_function_descriptor_alloc(defobj, def,
406 1.5 mycroft rela->r_addend);
407 1.5 mycroft if (tmp == (Elf_Addr)-1)
408 1.5 mycroft return -1;
409 1.4 mycroft
410 1.4 mycroft if (*where != tmp)
411 1.4 mycroft *where = tmp;
412 1.5 mycroft rdbg(dodebug, ("PLABEL32 %s in %s --> %p in %s",
413 1.7 mycroft obj->strtab + obj->symtab[symnum].st_name,
414 1.7 mycroft obj->path, (void *)*where, defobj->path));
415 1.5 mycroft } else {
416 1.5 mycroft /*
417 1.5 mycroft * This is a PLABEL for a static function, and
418 1.5 mycroft * the dynamic linker has both allocated a PLT
419 1.5 mycroft * entry for this function and told us where it
420 1.5 mycroft * is. We can safely use the PLT entry as the
421 1.5 mycroft * PLABEL because there should be no other
422 1.5 mycroft * PLABEL reloc referencing this function.
423 1.5 mycroft * This object should also have an IPLT
424 1.5 mycroft * relocation to initialize the PLT entry.
425 1.5 mycroft *
426 1.5 mycroft * The dynamic linker should also have ensured
427 1.5 mycroft * that the addend has the
428 1.5 mycroft * next-least-significant bit set; the
429 1.5 mycroft * $$dyncall millicode uses this to distinguish
430 1.5 mycroft * a PLABEL pointer from a plain function
431 1.5 mycroft * pointer.
432 1.5 mycroft */
433 1.5 mycroft tmp = (Elf_Addr)(obj->relocbase + rela->r_addend);
434 1.5 mycroft
435 1.5 mycroft if (*where != tmp)
436 1.5 mycroft *where = tmp;
437 1.5 mycroft rdbg(dodebug, ("PLABEL32 in %s --> %p",
438 1.4 mycroft obj->path, (void *)*where));
439 1.5 mycroft }
440 1.5 mycroft break;
441 1.4 mycroft
442 1.5 mycroft case R_TYPE(COPY):
443 1.4 mycroft /*
444 1.5 mycroft * These are deferred until all other relocations have
445 1.5 mycroft * been done. All we do here is make sure that the
446 1.5 mycroft * COPY relocation is not in a shared library. They
447 1.5 mycroft * are allowed only in executable files.
448 1.4 mycroft */
449 1.10 mycroft if (obj->isdynamic) {
450 1.5 mycroft _rtld_error(
451 1.5 mycroft "%s: Unexpected R_COPY relocation in shared library",
452 1.5 mycroft obj->path);
453 1.4 mycroft return -1;
454 1.5 mycroft }
455 1.5 mycroft rdbg(dodebug, ("COPY (avoid in main)"));
456 1.5 mycroft break;
457 1.4 mycroft
458 1.5 mycroft default:
459 1.5 mycroft rdbg(dodebug, ("sym = %lu, type = %lu, offset = %p, "
460 1.5 mycroft "addend = %p, contents = %p, symbol = %s",
461 1.6 mycroft symnum, (u_long)ELF_R_TYPE(rela->r_info),
462 1.5 mycroft (void *)rela->r_offset, (void *)rela->r_addend,
463 1.5 mycroft (void *)*where,
464 1.6 mycroft obj->strtab + obj->symtab[symnum].st_name));
465 1.5 mycroft _rtld_error("%s: Unsupported relocation type %ld "
466 1.5 mycroft "in non-PLT relocations\n",
467 1.5 mycroft obj->path, (u_long) ELF_R_TYPE(rela->r_info));
468 1.4 mycroft return -1;
469 1.4 mycroft }
470 1.8 mycroft }
471 1.8 mycroft return 0;
472 1.8 mycroft }
473 1.8 mycroft
474 1.8 mycroft int
475 1.8 mycroft _rtld_relocate_plt_lazy(obj, dodebug)
476 1.9 mycroft const Obj_Entry *obj;
477 1.8 mycroft bool dodebug;
478 1.8 mycroft {
479 1.8 mycroft const Elf_Rela *rela;
480 1.8 mycroft
481 1.8 mycroft for (rela = obj->pltrela; rela < obj->pltrelalim; rela++) {
482 1.8 mycroft Elf_Addr *where = (Elf_Addr *)(obj->relocbase + rela->r_offset);
483 1.8 mycroft Elf_Addr func_pc, func_sl;
484 1.8 mycroft
485 1.8 mycroft assert(ELF_R_TYPE(rela->r_info) == R_TYPE(IPLT));
486 1.8 mycroft
487 1.8 mycroft /*
488 1.8 mycroft * If this is an IPLT reloc for a static function,
489 1.8 mycroft * fully resolve the PLT entry now.
490 1.8 mycroft */
491 1.8 mycroft if (ELF_R_SYM(rela->r_info) == 0) {
492 1.8 mycroft func_pc = (Elf_Addr)(obj->relocbase + rela->r_addend);
493 1.8 mycroft func_sl = (Elf_Addr)HPPA_OBJ_SL(obj);
494 1.8 mycroft }
495 1.8 mycroft
496 1.8 mycroft /*
497 1.8 mycroft * Otherwise set up for lazy binding.
498 1.8 mycroft */
499 1.8 mycroft else {
500 1.8 mycroft /*
501 1.8 mycroft * This function pointer points to the PLT
502 1.8 mycroft * stub added by the linker, and instead of
503 1.8 mycroft * a shared linkage value, we stash this
504 1.8 mycroft * relocation's offset. The PLT stub has
505 1.8 mycroft * already been set up to transfer to
506 1.8 mycroft * _rtld_bind_start.
507 1.8 mycroft */
508 1.8 mycroft func_pc = ((Elf_Addr)HPPA_OBJ_GOT(obj)) - 16;
509 1.8 mycroft func_sl = (Elf_Addr)((caddr_t)rela - (caddr_t)obj->pltrela);
510 1.8 mycroft }
511 1.8 mycroft
512 1.8 mycroft /*
513 1.8 mycroft * Fill this PLT entry and return.
514 1.8 mycroft */
515 1.8 mycroft where[0] = func_pc;
516 1.8 mycroft where[1] = func_sl;
517 1.4 mycroft }
518 1.4 mycroft return 0;
519 1.1 fredette }
520