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