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 cache = mmap(NULL, bytes, PROT_READ|PROT_WRITE, MAP_ANON, -1, 0);
264 if (cache == MAP_FAILED)
267 relalim = (const Elf_Rela *)((caddr_t)obj->rela + obj->relasize);
268 for (rela = obj->rela; rela < relalim; rela++) {
269 if (reloc_nonplt_object(obj, rela, cache) < 0)
275 munmap(cache, bytes);
280 reloc_nonplt_object(Obj_Entry *obj, const Elf_Rela *rela, SymCache *cache)
282 const Obj_Entry *defobj;
290 where = (Elf_Addr *)(obj->relocbase + rela->r_offset);
291 where32 = (Elf_Word *)where;
295 type = ELF_R_TYPE(rela->r_info);
296 if (type == R_SPARC_NONE)
299 /* We do JMP_SLOTs below */
300 if (type == R_SPARC_JMP_SLOT)
303 /* COPY relocs are also handled elsewhere */
304 if (type == R_SPARC_COPY)
308 * Note: R_SPARC_UA16 must be numerically largest relocation type.
310 if (type > R_SPARC_UA16)
313 value = rela->r_addend;
316 * Handle relative relocs here, because we might not
317 * be able to access globals yet.
319 if (type == R_SPARC_RELATIVE) {
320 /* XXXX -- apparently we ignore the preexisting value */
321 *where = (Elf_Addr)(obj->relocbase + value);
326 * If we get here while relocating rtld itself, we will crash because
327 * a non-local variable is accessed.
329 if (RELOC_RESOLVE_SYMBOL(type)) {
331 /* Find the symbol */
332 def = find_symdef(ELF_R_SYM(rela->r_info), obj, &defobj,
337 /* Add in the symbol's absolute address */
338 value += (Elf_Addr)(defobj->relocbase + def->st_value);
341 if (RELOC_PC_RELATIVE(type))
342 value -= (Elf_Addr)where;
344 if (RELOC_BASE_RELATIVE(type)) {
346 * Note that even though sparcs use `Elf_rela' exclusively
347 * we still need the implicit memory addend in relocations
348 * referring to GOT entries. Undoubtedly, someone f*cked
349 * this up in the distant past, and now we're stuck with
350 * it in the name of compatibility for all eternity..
352 * In any case, the implicit and explicit should be mutually
353 * exclusive. We provide a check for that here.
355 /* XXXX -- apparently we ignore the preexisting value */
356 value += (Elf_Addr)(obj->relocbase);
359 mask = RELOC_VALUE_BITMASK(type);
360 value >>= RELOC_VALUE_RIGHTSHIFT(type);
363 if (RELOC_UNALIGNED(type)) {
364 /* Handle unaligned relocations. */
370 size = RELOC_TARGET_SIZE(type) / 8;
374 /* Read it in one byte at a time. */
375 for (i = 0; i < size; i++)
376 tmp = (tmp << 8) | ptr[i];
381 /* Write it back out. */
382 for (i = 0; i < size; i++)
383 ptr[i] = ((tmp >> ((size - i - 1) * 8)) & 0xff);
384 } else if (RELOC_TARGET_SIZE(type) > 32) {
396 reloc_plt(Obj_Entry *obj)
399 const Obj_Entry *defobj;
400 const Elf_Rela *relalim;
401 const Elf_Rela *rela;
406 relalim = (const Elf_Rela *)((char *)obj->pltrela + obj->pltrelasize);
407 for (rela = obj->pltrela; rela < relalim; rela++) {
408 if (rela->r_addend == 0)
410 assert(ELF_R_TYPE(rela->r_info) == R_SPARC_JMP_SLOT);
411 where = (Elf_Addr *)(obj->relocbase + rela->r_offset);
412 def = find_symdef(ELF_R_SYM(rela->r_info), obj, &defobj,
414 value = (Elf_Addr)(defobj->relocbase + def->st_value);
422 * Instruction templates:
424 #define BAA 0x10400000 /* ba,a %xcc, 0 */
425 #define SETHI 0x03000000 /* sethi %hi(0), %g1 */
426 #define JMP 0x81c06000 /* jmpl %g1+%lo(0), %g0 */
427 #define NOP 0x01000000 /* sethi %hi(0), %g0 */
428 #define OR 0x82806000 /* or %g1, 0, %g1 */
429 #define XOR 0x82c06000 /* xor %g1, 0, %g1 */
430 #define MOV71 0x8283a000 /* or %o7, 0, %g1 */
431 #define MOV17 0x9c806000 /* or %g1, 0, %o7 */
432 #define CALL 0x40000000 /* call 0 */
433 #define SLLX 0x8b407000 /* sllx %g1, 0, %g1 */
434 #define SETHIG5 0x0b000000 /* sethi %hi(0), %g5 */
435 #define ORG5 0x82804005 /* or %g1, %g5, %g1 */
438 /* %hi(v) with variable shift */
439 #define HIVAL(v, s) (((v) >> (s)) & 0x003fffff)
440 #define LOVAL(v) ((v) & 0x000003ff)
443 reloc_jmpslots(Obj_Entry *obj)
445 const Obj_Entry *defobj;
446 const Elf_Rela *relalim;
447 const Elf_Rela *rela;
452 relalim = (const Elf_Rela *)((char *)obj->pltrela + obj->pltrelasize);
453 for (rela = obj->pltrela; rela < relalim; rela++) {
454 assert(ELF_R_TYPE(rela->r_info) == R_SPARC_JMP_SLOT);
455 where = (Elf_Addr *)(obj->relocbase + rela->r_offset);
456 def = find_symdef(ELF_R_SYM(rela->r_info), obj, &defobj,
460 target = (Elf_Addr)(defobj->relocbase + def->st_value);
461 reloc_jmpslot(where, target, defobj, obj, (Elf_Rel *)rela);
463 obj->jmpslots_done = true;
468 reloc_jmpslot(Elf_Addr *wherep, Elf_Addr target, const Obj_Entry *obj,
469 const Obj_Entry *refobj, const Elf_Rel *rel)
471 const Elf_Rela *rela = (const Elf_Rela *)rel;
475 if (rela - refobj->pltrela < 32764) {
477 * At the PLT entry pointed at by `where', we now construct
478 * a direct transfer to the now fully resolved function
481 * A PLT entry is supposed to start by looking like this:
483 * sethi (. - .PLT0), %g1
492 * When we replace these entries we start from the second
493 * entry and do it in reverse order so the last thing we
494 * do is replace the branch. That allows us to change this
497 * We now need to find out how far we need to jump. We
498 * have a choice of several different relocation techniques
499 * which are increasingly expensive.
501 where = (Elf_Word *)wherep;
502 offset = ((Elf_Addr)where) - target;
503 if (offset <= (1L<<20) && offset >= -(1L<<20)) {
505 * We're within 1MB -- we can use a direct branch insn.
507 * We can generate this pattern:
509 * sethi %hi(. - .PLT0), %g1
519 where[1] = BAA | ((offset >> 2) &0x3fffff);
521 } else if (target >= 0 && target < (1L<<32)) {
523 * We're withing 32-bits of address zero.
525 * The resulting code in the jump slot is:
527 * sethi %hi(. - .PLT0), %g1
528 * sethi %hi(addr), %g1
537 where[2] = JMP | LOVAL(target);
539 where[1] = SETHI | HIVAL(target, 10);
541 } else if (target <= 0 && target > -(1L<<32)) {
543 * We're withing 32-bits of address -1.
545 * The resulting code in the jump slot is:
547 * sethi %hi(. - .PLT0), %g1
548 * sethi %hix(addr), %g1
549 * xor %g1, %lox(addr), %g1
559 where[2] = XOR | ((~target) & 0x00001fff);
561 where[1] = SETHI | HIVAL(~target, 10);
563 } else if (offset <= (1L<<32) && offset >= -((1L<<32) - 4)) {
565 * We're withing 32-bits -- we can use a direct call
568 * The resulting code in the jump slot is:
570 * sethi %hi(. - .PLT0), %g1
582 where[2] = CALL | ((offset >> 4) & 0x3fffffff);
586 } else if (offset >= 0 && offset < (1L<<44)) {
588 * We're withing 44 bits. We can generate this pattern:
590 * The resulting code in the jump slot is:
592 * sethi %hi(. - .PLT0), %g1
593 * sethi %h44(addr), %g1
594 * or %g1, %m44(addr), %g1
602 where[4] = JMP | LOVAL(offset);
604 where[3] = SLLX | 12;
606 where[2] = OR | (((offset) >> 12) & 0x00001fff);
608 where[1] = SETHI | HIVAL(offset, 22);
610 } else if (offset < 0 && offset > -(1L<<44)) {
612 * We're withing 44 bits. We can generate this pattern:
614 * The resulting code in the jump slot is:
616 * sethi %hi(. - .PLT0), %g1
617 * sethi %h44(-addr), %g1
618 * xor %g1, %m44(-addr), %g1
626 where[4] = JMP | LOVAL(offset);
628 where[3] = SLLX | 12;
630 where[2] = XOR | (((~offset) >> 12) & 0x00001fff);
632 where[1] = SETHI | HIVAL(~offset, 22);
636 * We need to load all 64-bits
638 * The resulting code in the jump slot is:
640 * sethi %hi(. - .PLT0), %g1
641 * sethi %hh(addr), %g1
642 * sethi %lm(addr), %g5
643 * or %g1, %hm(addr), %g1
650 where[6] = JMP | LOVAL(target);
654 where[4] = SLLX | 32;
656 where[3] = OR | LOVAL((target) >> 32);
658 where[2] = SETHIG5 | HIVAL(target, 10);
660 where[1] = SETHI | HIVAL(target, 42);
665 * This is a high PLT slot; the relocation offset specifies a
666 * pointer that needs to be frobbed; no actual code needs to
667 * be modified. The pointer to be calculated needs the addend
668 * added and the reference object relocation base subtraced.
670 *wherep = target + rela->r_addend -
671 (Elf_Addr)refobj->relocbase;
678 * Install rtld function call into this PLT slot.
680 #define SAVE 0x9de3bf50
681 #define SETHI_l0 0x21000000
682 #define SETHI_l1 0x23000000
683 #define OR_l0_l0 0xa0142000
684 #define SLLX_l0_32_l0 0xa12c3020
685 #define OR_l0_l1_l0 0xa0140011
686 #define JMPL_l0_o1 0x93c42000
687 #define MOV_g1_o0 0x90100001
690 init_pltgot(Obj_Entry *obj)
694 if (obj->pltgot != NULL) {
695 entry = (Elf_Word *)obj->pltgot;
696 install_plt(&entry[0], (Elf_Addr)_rtld_bind_start_0);
697 install_plt(&entry[8], (Elf_Addr)_rtld_bind_start_1);
698 obj->pltgot[8] = (Elf_Addr)obj;
703 install_plt(Elf_Word *pltgot, Elf_Addr proc)
707 pltgot[1] = SETHI_l0 | HIVAL(proc, 42);
709 pltgot[2] = SETHI_l1 | HIVAL(proc, 10);
711 pltgot[3] = OR_l0_l0 | LOVAL((proc) >> 32);
713 pltgot[4] = SLLX_l0_32_l0;
715 pltgot[5] = OR_l0_l1_l0;
717 pltgot[6] = JMPL_l0_o1 | LOVAL(proc);
719 pltgot[7] = MOV_g1_o0;
724 allocate_initial_tls(Obj_Entry *objs)
729 * Fix the size of the static TLS block by using the maximum
730 * offset allocated so far and adding a bit for dynamic modules to
733 tls_static_space = tls_last_offset + RTLD_STATIC_TLS_EXTRA;
734 tpval = allocate_tls(objs, NULL, 3*sizeof(Elf_Addr), sizeof(Elf_Addr));
735 __asm __volatile("mov %0, %%g7" : : "r" (tpval));
738 void *__tls_get_addr(tls_index *ti)
740 register Elf_Addr** tp __asm__("%g7");
742 return tls_get_addr_common(tp, ti->ti_module, ti->ti_offset);