1 /* $NetBSD: mdreloc.c,v 1.5 2001/04/25 12:24:51 kleink Exp $ */
4 * Copyright (c) 2000 Eduardo Horvath.
5 * Copyright (c) 1999 The NetBSD Foundation, Inc.
8 * This code is derived from software contributed to The NetBSD Foundation
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the NetBSD
22 * Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
42 #include <sys/param.h>
55 * The following table holds for each relocation type:
56 * - the width in bits of the memory location the relocation
57 * applies to (not currently used)
58 * - the number of bits the relocation value must be shifted to the
59 * right (i.e. discard least significant bits) to fit into
60 * the appropriate field in the instruction word.
61 * - flags indicating whether
62 * * the relocation involves a symbol
63 * * the relocation is relative to the current position
64 * * the relocation is for a GOT entry
65 * * the relocation is relative to the load address
68 #define _RF_S 0x80000000 /* Resolve symbol */
69 #define _RF_A 0x40000000 /* Use addend */
70 #define _RF_P 0x20000000 /* Location relative */
71 #define _RF_G 0x10000000 /* GOT offset */
72 #define _RF_B 0x08000000 /* Load address relative */
73 #define _RF_U 0x04000000 /* Unaligned */
74 #define _RF_SZ(s) (((s) & 0xff) << 8) /* memory target size */
75 #define _RF_RS(s) ( (s) & 0xff) /* right shift */
76 static int reloc_target_flags[] = {
78 _RF_S|_RF_A| _RF_SZ(8) | _RF_RS(0), /* RELOC_8 */
79 _RF_S|_RF_A| _RF_SZ(16) | _RF_RS(0), /* RELOC_16 */
80 _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(0), /* RELOC_32 */
81 _RF_S|_RF_A|_RF_P| _RF_SZ(8) | _RF_RS(0), /* DISP_8 */
82 _RF_S|_RF_A|_RF_P| _RF_SZ(16) | _RF_RS(0), /* DISP_16 */
83 _RF_S|_RF_A|_RF_P| _RF_SZ(32) | _RF_RS(0), /* DISP_32 */
84 _RF_S|_RF_A|_RF_P| _RF_SZ(32) | _RF_RS(2), /* WDISP_30 */
85 _RF_S|_RF_A|_RF_P| _RF_SZ(32) | _RF_RS(2), /* WDISP_22 */
86 _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(10), /* HI22 */
87 _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(0), /* 22 */
88 _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(0), /* 13 */
89 _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(0), /* LO10 */
90 _RF_G| _RF_SZ(32) | _RF_RS(0), /* GOT10 */
91 _RF_G| _RF_SZ(32) | _RF_RS(0), /* GOT13 */
92 _RF_G| _RF_SZ(32) | _RF_RS(10), /* GOT22 */
93 _RF_S|_RF_A|_RF_P| _RF_SZ(32) | _RF_RS(0), /* PC10 */
94 _RF_S|_RF_A|_RF_P| _RF_SZ(32) | _RF_RS(10), /* PC22 */
95 _RF_A|_RF_P| _RF_SZ(32) | _RF_RS(2), /* WPLT30 */
96 _RF_SZ(32) | _RF_RS(0), /* COPY */
97 _RF_S|_RF_A| _RF_SZ(64) | _RF_RS(0), /* GLOB_DAT */
98 _RF_SZ(32) | _RF_RS(0), /* JMP_SLOT */
99 _RF_A| _RF_B| _RF_SZ(64) | _RF_RS(0), /* RELATIVE */
100 _RF_S|_RF_A| _RF_U| _RF_SZ(32) | _RF_RS(0), /* UA_32 */
102 _RF_A| _RF_SZ(32) | _RF_RS(0), /* PLT32 */
103 _RF_A| _RF_SZ(32) | _RF_RS(10), /* HIPLT22 */
104 _RF_A| _RF_SZ(32) | _RF_RS(0), /* LOPLT10 */
105 _RF_A|_RF_P| _RF_SZ(32) | _RF_RS(0), /* PCPLT32 */
106 _RF_A|_RF_P| _RF_SZ(32) | _RF_RS(10), /* PCPLT22 */
107 _RF_A|_RF_P| _RF_SZ(32) | _RF_RS(0), /* PCPLT10 */
108 _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(0), /* 10 */
109 _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(0), /* 11 */
110 _RF_S|_RF_A| _RF_SZ(64) | _RF_RS(0), /* 64 */
111 _RF_S|_RF_A|/*extra*/ _RF_SZ(32) | _RF_RS(0), /* OLO10 */
112 _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(42), /* HH22 */
113 _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(32), /* HM10 */
114 _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(10), /* LM22 */
115 _RF_S|_RF_A|_RF_P| _RF_SZ(32) | _RF_RS(42), /* PC_HH22 */
116 _RF_S|_RF_A|_RF_P| _RF_SZ(32) | _RF_RS(32), /* PC_HM10 */
117 _RF_S|_RF_A|_RF_P| _RF_SZ(32) | _RF_RS(10), /* PC_LM22 */
118 _RF_S|_RF_A|_RF_P| _RF_SZ(32) | _RF_RS(2), /* WDISP16 */
119 _RF_S|_RF_A|_RF_P| _RF_SZ(32) | _RF_RS(2), /* WDISP19 */
120 _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(0), /* GLOB_JMP */
121 _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(0), /* 7 */
122 _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(0), /* 5 */
123 _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(0), /* 6 */
124 _RF_S|_RF_A|_RF_P| _RF_SZ(64) | _RF_RS(0), /* DISP64 */
125 _RF_A| _RF_SZ(64) | _RF_RS(0), /* PLT64 */
126 _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(10), /* HIX22 */
127 _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(0), /* LOX10 */
128 _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(22), /* H44 */
129 _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(12), /* M44 */
130 _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(0), /* L44 */
131 _RF_S|_RF_A| _RF_SZ(64) | _RF_RS(0), /* REGISTER */
132 _RF_S|_RF_A| _RF_U| _RF_SZ(64) | _RF_RS(0), /* UA64 */
133 _RF_S|_RF_A| _RF_U| _RF_SZ(16) | _RF_RS(0), /* UA16 */
137 static const char *reloc_names[] = {
138 "NONE", "RELOC_8", "RELOC_16", "RELOC_32", "DISP_8",
139 "DISP_16", "DISP_32", "WDISP_30", "WDISP_22", "HI22",
140 "22", "13", "LO10", "GOT10", "GOT13",
141 "GOT22", "PC10", "PC22", "WPLT30", "COPY",
142 "GLOB_DAT", "JMP_SLOT", "RELATIVE", "UA_32", "PLT32",
143 "HIPLT22", "LOPLT10", "LOPLT10", "PCPLT22", "PCPLT32",
144 "10", "11", "64", "OLO10", "HH22",
145 "HM10", "LM22", "PC_HH22", "PC_HM10", "PC_LM22",
146 "WDISP16", "WDISP19", "GLOB_JMP", "7", "5", "6",
147 "DISP64", "PLT64", "HIX22", "LOX10", "H44", "M44",
148 "L44", "REGISTER", "UA64", "UA16"
152 #define RELOC_RESOLVE_SYMBOL(t) ((reloc_target_flags[t] & _RF_S) != 0)
153 #define RELOC_PC_RELATIVE(t) ((reloc_target_flags[t] & _RF_P) != 0)
154 #define RELOC_BASE_RELATIVE(t) ((reloc_target_flags[t] & _RF_B) != 0)
155 #define RELOC_UNALIGNED(t) ((reloc_target_flags[t] & _RF_U) != 0)
156 #define RELOC_USE_ADDEND(t) ((reloc_target_flags[t] & _RF_A) != 0)
157 #define RELOC_TARGET_SIZE(t) ((reloc_target_flags[t] >> 8) & 0xff)
158 #define RELOC_VALUE_RIGHTSHIFT(t) (reloc_target_flags[t] & 0xff)
160 static long reloc_target_bitmask[] = {
161 #define _BM(x) (~(-(1ULL << (x))))
163 _BM(8), _BM(16), _BM(32), /* RELOC_8, _16, _32 */
164 _BM(8), _BM(16), _BM(32), /* DISP8, DISP16, DISP32 */
165 _BM(30), _BM(22), /* WDISP30, WDISP22 */
166 _BM(22), _BM(22), /* HI22, _22 */
167 _BM(13), _BM(10), /* RELOC_13, _LO10 */
168 _BM(10), _BM(13), _BM(22), /* GOT10, GOT13, GOT22 */
169 _BM(10), _BM(22), /* _PC10, _PC22 */
170 _BM(30), 0, /* _WPLT30, _COPY */
171 _BM(32), _BM(32), _BM(32), /* _GLOB_DAT, JMP_SLOT, _RELATIVE */
172 _BM(32), _BM(32), /* _UA32, PLT32 */
173 _BM(22), _BM(10), /* _HIPLT22, LOPLT10 */
174 _BM(32), _BM(22), _BM(10), /* _PCPLT32, _PCPLT22, _PCPLT10 */
175 _BM(10), _BM(11), -1, /* _10, _11, _64 */
176 _BM(10), _BM(22), /* _OLO10, _HH22 */
177 _BM(10), _BM(22), /* _HM10, _LM22 */
178 _BM(22), _BM(10), _BM(22), /* _PC_HH22, _PC_HM10, _PC_LM22 */
179 _BM(16), _BM(19), /* _WDISP16, _WDISP19 */
181 _BM(7), _BM(5), _BM(6), /* _7, _5, _6 */
182 -1, -1, /* DISP64, PLT64 */
183 _BM(22), _BM(13), /* HIX22, LOX10 */
184 _BM(22), _BM(10), _BM(13), /* H44, M44, L44 */
185 -1, -1, _BM(16), /* REGISTER, UA64, UA16 */
188 #define RELOC_VALUE_BITMASK(t) (reloc_target_bitmask[t])
191 #define flush(va, offs) \
192 __asm __volatile("flush %0 + %1" : : "r" (va), "I" (offs));
194 static int reloc_nonplt_object(Obj_Entry *obj, const Elf_Rela *rela,
196 static void install_plt(Elf_Word *pltgot, Elf_Addr proc);
198 extern char _rtld_bind_start_0[];
199 extern char _rtld_bind_start_1[];
202 do_copy_relocations(Obj_Entry *dstobj)
204 const Elf_Rela *relalim;
205 const Elf_Rela *rela;
206 const Elf_Sym *dstsym;
207 const Elf_Sym *srcsym;
216 assert(dstobj->mainprog); /* COPY relocations are invalid elsewhere */
218 relalim = (const Elf_Rela *)((caddr_t)dstobj->rela + dstobj->relasize);
219 for (rela = dstobj->rela; rela < relalim; rela++) {
220 if (ELF_R_TYPE(rela->r_info) == R_SPARC_COPY) {
221 dstaddr = (void *)(dstobj->relocbase + rela->r_offset);
222 dstsym = dstobj->symtab + ELF_R_SYM(rela->r_info);
223 name = dstobj->strtab + dstsym->st_name;
224 hash = elf_hash(name);
225 size = dstsym->st_size;
226 ve = fetch_ventry(dstobj, ELF_R_SYM(rela->r_info));
228 for (srcobj = dstobj->next; srcobj != NULL;
229 srcobj = srcobj->next)
230 if ((srcsym = symlook_obj(name, hash, srcobj,
234 if (srcobj == NULL) {
235 _rtld_error("Undefined symbol \"%s\""
236 "referenced from COPY relocation"
237 "in %s", name, dstobj->path);
241 srcaddr = (const void *)(srcobj->relocbase +
243 memcpy(dstaddr, srcaddr, size);
251 reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld)
253 const Elf_Rela *relalim;
254 const Elf_Rela *rela;
256 int bytes = obj->nchains * sizeof(SymCache);
260 * The dynamic loader may be called from a thread, we have
261 * limited amounts of stack available so we cannot use alloca().
263 if (obj != obj_rtld) {
264 cache = mmap(NULL, bytes, PROT_READ|PROT_WRITE, MAP_ANON,
266 if (cache == MAP_FAILED)
271 relalim = (const Elf_Rela *)((caddr_t)obj->rela + obj->relasize);
272 for (rela = obj->rela; rela < relalim; rela++) {
273 if (reloc_nonplt_object(obj, rela, cache) < 0)
279 munmap(cache, bytes);
284 reloc_nonplt_object(Obj_Entry *obj, const Elf_Rela *rela, SymCache *cache)
286 const Obj_Entry *defobj;
294 where = (Elf_Addr *)(obj->relocbase + rela->r_offset);
295 where32 = (Elf_Word *)where;
299 type = ELF_R_TYPE(rela->r_info);
300 if (type == R_SPARC_NONE)
303 /* We do JMP_SLOTs below */
304 if (type == R_SPARC_JMP_SLOT)
307 /* COPY relocs are also handled elsewhere */
308 if (type == R_SPARC_COPY)
312 * Note: R_SPARC_UA16 must be numerically largest relocation type.
314 if (type > R_SPARC_UA16)
317 value = rela->r_addend;
320 * Handle relative relocs here, because we might not
321 * be able to access globals yet.
323 if (type == R_SPARC_RELATIVE) {
324 /* XXXX -- apparently we ignore the preexisting value */
325 *where = (Elf_Addr)(obj->relocbase + value);
330 * If we get here while relocating rtld itself, we will crash because
331 * a non-local variable is accessed.
333 if (RELOC_RESOLVE_SYMBOL(type)) {
335 /* Find the symbol */
336 def = find_symdef(ELF_R_SYM(rela->r_info), obj, &defobj,
341 /* Add in the symbol's absolute address */
342 value += (Elf_Addr)(defobj->relocbase + def->st_value);
345 if (RELOC_PC_RELATIVE(type))
346 value -= (Elf_Addr)where;
348 if (RELOC_BASE_RELATIVE(type)) {
350 * Note that even though sparcs use `Elf_rela' exclusively
351 * we still need the implicit memory addend in relocations
352 * referring to GOT entries. Undoubtedly, someone f*cked
353 * this up in the distant past, and now we're stuck with
354 * it in the name of compatibility for all eternity..
356 * In any case, the implicit and explicit should be mutually
357 * exclusive. We provide a check for that here.
359 /* XXXX -- apparently we ignore the preexisting value */
360 value += (Elf_Addr)(obj->relocbase);
363 mask = RELOC_VALUE_BITMASK(type);
364 value >>= RELOC_VALUE_RIGHTSHIFT(type);
367 if (RELOC_UNALIGNED(type)) {
368 /* Handle unaligned relocations. */
374 size = RELOC_TARGET_SIZE(type) / 8;
378 /* Read it in one byte at a time. */
379 for (i = 0; i < size; i++)
380 tmp = (tmp << 8) | ptr[i];
385 /* Write it back out. */
386 for (i = 0; i < size; i++)
387 ptr[i] = ((tmp >> ((size - i - 1) * 8)) & 0xff);
388 } else if (RELOC_TARGET_SIZE(type) > 32) {
400 reloc_plt(Obj_Entry *obj)
403 const Obj_Entry *defobj;
404 const Elf_Rela *relalim;
405 const Elf_Rela *rela;
410 relalim = (const Elf_Rela *)((char *)obj->pltrela + obj->pltrelasize);
411 for (rela = obj->pltrela; rela < relalim; rela++) {
412 if (rela->r_addend == 0)
414 assert(ELF_R_TYPE(rela->r_info) == R_SPARC_JMP_SLOT);
415 where = (Elf_Addr *)(obj->relocbase + rela->r_offset);
416 def = find_symdef(ELF_R_SYM(rela->r_info), obj, &defobj,
418 value = (Elf_Addr)(defobj->relocbase + def->st_value);
426 * Instruction templates:
428 #define BAA 0x10400000 /* ba,a %xcc, 0 */
429 #define SETHI 0x03000000 /* sethi %hi(0), %g1 */
430 #define JMP 0x81c06000 /* jmpl %g1+%lo(0), %g0 */
431 #define NOP 0x01000000 /* sethi %hi(0), %g0 */
432 #define OR 0x82806000 /* or %g1, 0, %g1 */
433 #define XOR 0x82c06000 /* xor %g1, 0, %g1 */
434 #define MOV71 0x8283a000 /* or %o7, 0, %g1 */
435 #define MOV17 0x9c806000 /* or %g1, 0, %o7 */
436 #define CALL 0x40000000 /* call 0 */
437 #define SLLX 0x8b407000 /* sllx %g1, 0, %g1 */
438 #define SETHIG5 0x0b000000 /* sethi %hi(0), %g5 */
439 #define ORG5 0x82804005 /* or %g1, %g5, %g1 */
442 /* %hi(v) with variable shift */
443 #define HIVAL(v, s) (((v) >> (s)) & 0x003fffff)
444 #define LOVAL(v) ((v) & 0x000003ff)
447 reloc_jmpslots(Obj_Entry *obj)
449 const Obj_Entry *defobj;
450 const Elf_Rela *relalim;
451 const Elf_Rela *rela;
456 relalim = (const Elf_Rela *)((char *)obj->pltrela + obj->pltrelasize);
457 for (rela = obj->pltrela; rela < relalim; rela++) {
458 assert(ELF_R_TYPE(rela->r_info) == R_SPARC_JMP_SLOT);
459 where = (Elf_Addr *)(obj->relocbase + rela->r_offset);
460 def = find_symdef(ELF_R_SYM(rela->r_info), obj, &defobj,
464 target = (Elf_Addr)(defobj->relocbase + def->st_value);
465 reloc_jmpslot(where, target, defobj, obj, (Elf_Rel *)rela);
467 obj->jmpslots_done = true;
472 reloc_jmpslot(Elf_Addr *wherep, Elf_Addr target, const Obj_Entry *obj,
473 const Obj_Entry *refobj, const Elf_Rel *rel)
475 const Elf_Rela *rela = (const Elf_Rela *)rel;
479 if (rela - refobj->pltrela < 32764) {
481 * At the PLT entry pointed at by `where', we now construct
482 * a direct transfer to the now fully resolved function
485 * A PLT entry is supposed to start by looking like this:
487 * sethi (. - .PLT0), %g1
496 * When we replace these entries we start from the second
497 * entry and do it in reverse order so the last thing we
498 * do is replace the branch. That allows us to change this
501 * We now need to find out how far we need to jump. We
502 * have a choice of several different relocation techniques
503 * which are increasingly expensive.
505 where = (Elf_Word *)wherep;
506 offset = ((Elf_Addr)where) - target;
507 if (offset <= (1L<<20) && offset >= -(1L<<20)) {
509 * We're within 1MB -- we can use a direct branch insn.
511 * We can generate this pattern:
513 * sethi %hi(. - .PLT0), %g1
523 where[1] = BAA | ((offset >> 2) &0x3fffff);
525 } else if (target >= 0 && target < (1L<<32)) {
527 * We're withing 32-bits of address zero.
529 * The resulting code in the jump slot is:
531 * sethi %hi(. - .PLT0), %g1
532 * sethi %hi(addr), %g1
541 where[2] = JMP | LOVAL(target);
543 where[1] = SETHI | HIVAL(target, 10);
545 } else if (target <= 0 && target > -(1L<<32)) {
547 * We're withing 32-bits of address -1.
549 * The resulting code in the jump slot is:
551 * sethi %hi(. - .PLT0), %g1
552 * sethi %hix(addr), %g1
553 * xor %g1, %lox(addr), %g1
563 where[2] = XOR | ((~target) & 0x00001fff);
565 where[1] = SETHI | HIVAL(~target, 10);
567 } else if (offset <= (1L<<32) && offset >= -((1L<<32) - 4)) {
569 * We're withing 32-bits -- we can use a direct call
572 * The resulting code in the jump slot is:
574 * sethi %hi(. - .PLT0), %g1
586 where[2] = CALL | ((offset >> 4) & 0x3fffffff);
590 } else if (offset >= 0 && offset < (1L<<44)) {
592 * We're withing 44 bits. We can generate this pattern:
594 * The resulting code in the jump slot is:
596 * sethi %hi(. - .PLT0), %g1
597 * sethi %h44(addr), %g1
598 * or %g1, %m44(addr), %g1
606 where[4] = JMP | LOVAL(offset);
608 where[3] = SLLX | 12;
610 where[2] = OR | (((offset) >> 12) & 0x00001fff);
612 where[1] = SETHI | HIVAL(offset, 22);
614 } else if (offset < 0 && offset > -(1L<<44)) {
616 * We're withing 44 bits. We can generate this pattern:
618 * The resulting code in the jump slot is:
620 * sethi %hi(. - .PLT0), %g1
621 * sethi %h44(-addr), %g1
622 * xor %g1, %m44(-addr), %g1
630 where[4] = JMP | LOVAL(offset);
632 where[3] = SLLX | 12;
634 where[2] = XOR | (((~offset) >> 12) & 0x00001fff);
636 where[1] = SETHI | HIVAL(~offset, 22);
640 * We need to load all 64-bits
642 * The resulting code in the jump slot is:
644 * sethi %hi(. - .PLT0), %g1
645 * sethi %hh(addr), %g1
646 * sethi %lm(addr), %g5
647 * or %g1, %hm(addr), %g1
654 where[6] = JMP | LOVAL(target);
658 where[4] = SLLX | 32;
660 where[3] = OR | LOVAL((target) >> 32);
662 where[2] = SETHIG5 | HIVAL(target, 10);
664 where[1] = SETHI | HIVAL(target, 42);
669 * This is a high PLT slot; the relocation offset specifies a
670 * pointer that needs to be frobbed; no actual code needs to
671 * be modified. The pointer to be calculated needs the addend
672 * added and the reference object relocation base subtraced.
674 *wherep = target + rela->r_addend -
675 (Elf_Addr)refobj->relocbase;
682 * Install rtld function call into this PLT slot.
684 #define SAVE 0x9de3bf50
685 #define SETHI_l0 0x21000000
686 #define SETHI_l1 0x23000000
687 #define OR_l0_l0 0xa0142000
688 #define SLLX_l0_32_l0 0xa12c3020
689 #define OR_l0_l1_l0 0xa0140011
690 #define JMPL_l0_o1 0x93c42000
691 #define MOV_g1_o0 0x90100001
694 init_pltgot(Obj_Entry *obj)
698 if (obj->pltgot != NULL) {
699 entry = (Elf_Word *)obj->pltgot;
700 install_plt(&entry[0], (Elf_Addr)_rtld_bind_start_0);
701 install_plt(&entry[8], (Elf_Addr)_rtld_bind_start_1);
702 obj->pltgot[8] = (Elf_Addr)obj;
707 install_plt(Elf_Word *pltgot, Elf_Addr proc)
711 pltgot[1] = SETHI_l0 | HIVAL(proc, 42);
713 pltgot[2] = SETHI_l1 | HIVAL(proc, 10);
715 pltgot[3] = OR_l0_l0 | LOVAL((proc) >> 32);
717 pltgot[4] = SLLX_l0_32_l0;
719 pltgot[5] = OR_l0_l1_l0;
721 pltgot[6] = JMPL_l0_o1 | LOVAL(proc);
723 pltgot[7] = MOV_g1_o0;
728 allocate_initial_tls(Obj_Entry *objs)
733 * Fix the size of the static TLS block by using the maximum
734 * offset allocated so far and adding a bit for dynamic modules to
737 tls_static_space = tls_last_offset + RTLD_STATIC_TLS_EXTRA;
738 tpval = allocate_tls(objs, NULL, 3*sizeof(Elf_Addr), sizeof(Elf_Addr));
739 __asm __volatile("mov %0, %%g7" : : "r" (tpval));
742 void *__tls_get_addr(tls_index *ti)
744 register Elf_Addr** tp __asm__("%g7");
746 return tls_get_addr_common(tp, ti->ti_module, ti->ti_offset);