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.
40 #include <sys/cdefs.h>
41 __FBSDID("$FreeBSD$");
43 #include <sys/param.h>
56 * The following table holds for each relocation type:
57 * - the width in bits of the memory location the relocation
58 * applies to (not currently used)
59 * - the number of bits the relocation value must be shifted to the
60 * right (i.e. discard least significant bits) to fit into
61 * the appropriate field in the instruction word.
62 * - flags indicating whether
63 * * the relocation involves a symbol
64 * * the relocation is relative to the current position
65 * * the relocation is for a GOT entry
66 * * the relocation is relative to the load address
69 #define _RF_S 0x80000000 /* Resolve symbol */
70 #define _RF_A 0x40000000 /* Use addend */
71 #define _RF_P 0x20000000 /* Location relative */
72 #define _RF_G 0x10000000 /* GOT offset */
73 #define _RF_B 0x08000000 /* Load address relative */
74 #define _RF_U 0x04000000 /* Unaligned */
75 #define _RF_SZ(s) (((s) & 0xff) << 8) /* memory target size */
76 #define _RF_RS(s) ( (s) & 0xff) /* right shift */
77 static const int reloc_target_flags[] = {
79 _RF_S|_RF_A| _RF_SZ(8) | _RF_RS(0), /* RELOC_8 */
80 _RF_S|_RF_A| _RF_SZ(16) | _RF_RS(0), /* RELOC_16 */
81 _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(0), /* RELOC_32 */
82 _RF_S|_RF_A|_RF_P| _RF_SZ(8) | _RF_RS(0), /* DISP_8 */
83 _RF_S|_RF_A|_RF_P| _RF_SZ(16) | _RF_RS(0), /* DISP_16 */
84 _RF_S|_RF_A|_RF_P| _RF_SZ(32) | _RF_RS(0), /* DISP_32 */
85 _RF_S|_RF_A|_RF_P| _RF_SZ(32) | _RF_RS(2), /* WDISP_30 */
86 _RF_S|_RF_A|_RF_P| _RF_SZ(32) | _RF_RS(2), /* WDISP_22 */
87 _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(10), /* HI22 */
88 _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(0), /* 22 */
89 _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(0), /* 13 */
90 _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(0), /* LO10 */
91 _RF_G| _RF_SZ(32) | _RF_RS(0), /* GOT10 */
92 _RF_G| _RF_SZ(32) | _RF_RS(0), /* GOT13 */
93 _RF_G| _RF_SZ(32) | _RF_RS(10), /* GOT22 */
94 _RF_S|_RF_A|_RF_P| _RF_SZ(32) | _RF_RS(0), /* PC10 */
95 _RF_S|_RF_A|_RF_P| _RF_SZ(32) | _RF_RS(10), /* PC22 */
96 _RF_A|_RF_P| _RF_SZ(32) | _RF_RS(2), /* WPLT30 */
97 _RF_SZ(32) | _RF_RS(0), /* COPY */
98 _RF_S|_RF_A| _RF_SZ(64) | _RF_RS(0), /* GLOB_DAT */
99 _RF_SZ(32) | _RF_RS(0), /* JMP_SLOT */
100 _RF_A| _RF_B| _RF_SZ(64) | _RF_RS(0), /* RELATIVE */
101 _RF_S|_RF_A| _RF_U| _RF_SZ(32) | _RF_RS(0), /* UA_32 */
103 _RF_A| _RF_SZ(32) | _RF_RS(0), /* PLT32 */
104 _RF_A| _RF_SZ(32) | _RF_RS(10), /* HIPLT22 */
105 _RF_A| _RF_SZ(32) | _RF_RS(0), /* LOPLT10 */
106 _RF_A|_RF_P| _RF_SZ(32) | _RF_RS(0), /* PCPLT32 */
107 _RF_A|_RF_P| _RF_SZ(32) | _RF_RS(10), /* PCPLT22 */
108 _RF_A|_RF_P| _RF_SZ(32) | _RF_RS(0), /* PCPLT10 */
109 _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(0), /* 10 */
110 _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(0), /* 11 */
111 _RF_S|_RF_A| _RF_SZ(64) | _RF_RS(0), /* 64 */
112 _RF_S|_RF_A|/*extra*/ _RF_SZ(32) | _RF_RS(0), /* OLO10 */
113 _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(42), /* HH22 */
114 _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(32), /* HM10 */
115 _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(10), /* LM22 */
116 _RF_S|_RF_A|_RF_P| _RF_SZ(32) | _RF_RS(42), /* PC_HH22 */
117 _RF_S|_RF_A|_RF_P| _RF_SZ(32) | _RF_RS(32), /* PC_HM10 */
118 _RF_S|_RF_A|_RF_P| _RF_SZ(32) | _RF_RS(10), /* PC_LM22 */
119 _RF_S|_RF_A|_RF_P| _RF_SZ(32) | _RF_RS(2), /* WDISP16 */
120 _RF_S|_RF_A|_RF_P| _RF_SZ(32) | _RF_RS(2), /* WDISP19 */
121 _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(0), /* GLOB_JMP */
122 _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(0), /* 7 */
123 _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(0), /* 5 */
124 _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(0), /* 6 */
125 _RF_S|_RF_A|_RF_P| _RF_SZ(64) | _RF_RS(0), /* DISP64 */
126 _RF_A| _RF_SZ(64) | _RF_RS(0), /* PLT64 */
127 _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(10), /* HIX22 */
128 _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(0), /* LOX10 */
129 _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(22), /* H44 */
130 _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(12), /* M44 */
131 _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(0), /* L44 */
132 _RF_S|_RF_A| _RF_SZ(64) | _RF_RS(0), /* REGISTER */
133 _RF_S|_RF_A| _RF_U| _RF_SZ(64) | _RF_RS(0), /* UA64 */
134 _RF_S|_RF_A| _RF_U| _RF_SZ(16) | _RF_RS(0), /* UA16 */
138 static const char *reloc_names[] = {
139 "NONE", "RELOC_8", "RELOC_16", "RELOC_32", "DISP_8",
140 "DISP_16", "DISP_32", "WDISP_30", "WDISP_22", "HI22",
141 "22", "13", "LO10", "GOT10", "GOT13",
142 "GOT22", "PC10", "PC22", "WPLT30", "COPY",
143 "GLOB_DAT", "JMP_SLOT", "RELATIVE", "UA_32", "PLT32",
144 "HIPLT22", "LOPLT10", "LOPLT10", "PCPLT22", "PCPLT32",
145 "10", "11", "64", "OLO10", "HH22",
146 "HM10", "LM22", "PC_HH22", "PC_HM10", "PC_LM22",
147 "WDISP16", "WDISP19", "GLOB_JMP", "7", "5", "6",
148 "DISP64", "PLT64", "HIX22", "LOX10", "H44", "M44",
149 "L44", "REGISTER", "UA64", "UA16"
153 #define RELOC_RESOLVE_SYMBOL(t) ((reloc_target_flags[t] & _RF_S) != 0)
154 #define RELOC_PC_RELATIVE(t) ((reloc_target_flags[t] & _RF_P) != 0)
155 #define RELOC_BASE_RELATIVE(t) ((reloc_target_flags[t] & _RF_B) != 0)
156 #define RELOC_UNALIGNED(t) ((reloc_target_flags[t] & _RF_U) != 0)
157 #define RELOC_USE_ADDEND(t) ((reloc_target_flags[t] & _RF_A) != 0)
158 #define RELOC_TARGET_SIZE(t) ((reloc_target_flags[t] >> 8) & 0xff)
159 #define RELOC_VALUE_RIGHTSHIFT(t) (reloc_target_flags[t] & 0xff)
161 static const long reloc_target_bitmask[] = {
162 #define _BM(x) (~(-(1ULL << (x))))
164 _BM(8), _BM(16), _BM(32), /* RELOC_8, _16, _32 */
165 _BM(8), _BM(16), _BM(32), /* DISP8, DISP16, DISP32 */
166 _BM(30), _BM(22), /* WDISP30, WDISP22 */
167 _BM(22), _BM(22), /* HI22, _22 */
168 _BM(13), _BM(10), /* RELOC_13, _LO10 */
169 _BM(10), _BM(13), _BM(22), /* GOT10, GOT13, GOT22 */
170 _BM(10), _BM(22), /* _PC10, _PC22 */
171 _BM(30), 0, /* _WPLT30, _COPY */
172 _BM(32), _BM(32), _BM(32), /* _GLOB_DAT, JMP_SLOT, _RELATIVE */
173 _BM(32), _BM(32), /* _UA32, PLT32 */
174 _BM(22), _BM(10), /* _HIPLT22, LOPLT10 */
175 _BM(32), _BM(22), _BM(10), /* _PCPLT32, _PCPLT22, _PCPLT10 */
176 _BM(10), _BM(11), -1, /* _10, _11, _64 */
177 _BM(13), _BM(22), /* _OLO10, _HH22 */
178 _BM(10), _BM(22), /* _HM10, _LM22 */
179 _BM(22), _BM(10), _BM(22), /* _PC_HH22, _PC_HM10, _PC_LM22 */
180 _BM(16), _BM(19), /* _WDISP16, _WDISP19 */
182 _BM(7), _BM(5), _BM(6), /* _7, _5, _6 */
183 -1, -1, /* DISP64, PLT64 */
184 _BM(22), _BM(13), /* HIX22, LOX10 */
185 _BM(22), _BM(10), _BM(13), /* H44, M44, L44 */
186 -1, -1, _BM(16), /* REGISTER, UA64, UA16 */
189 #define RELOC_VALUE_BITMASK(t) (reloc_target_bitmask[t])
192 #define flush(va, offs) \
193 __asm __volatile("flush %0 + %1" : : "r" (va), "I" (offs));
195 static int reloc_nonplt_object(Obj_Entry *obj, const Elf_Rela *rela,
197 static void install_plt(Elf_Word *pltgot, Elf_Addr proc);
199 extern char _rtld_bind_start_0[];
200 extern char _rtld_bind_start_1[];
203 do_copy_relocations(Obj_Entry *dstobj)
205 const Elf_Rela *relalim;
206 const Elf_Rela *rela;
207 const Elf_Sym *dstsym;
208 const Elf_Sym *srcsym;
217 assert(dstobj->mainprog); /* COPY relocations are invalid elsewhere */
219 relalim = (const Elf_Rela *)((caddr_t)dstobj->rela + dstobj->relasize);
220 for (rela = dstobj->rela; rela < relalim; rela++) {
221 if (ELF_R_TYPE(rela->r_info) == R_SPARC_COPY) {
222 dstaddr = (void *)(dstobj->relocbase + rela->r_offset);
223 dstsym = dstobj->symtab + ELF_R_SYM(rela->r_info);
224 name = dstobj->strtab + dstsym->st_name;
225 hash = elf_hash(name);
226 size = dstsym->st_size;
227 ve = fetch_ventry(dstobj, ELF_R_SYM(rela->r_info));
229 for (srcobj = dstobj->next; srcobj != NULL;
230 srcobj = srcobj->next)
231 if ((srcsym = symlook_obj(name, hash, srcobj,
235 if (srcobj == NULL) {
236 _rtld_error("Undefined symbol \"%s\""
237 "referenced from COPY relocation"
238 "in %s", name, dstobj->path);
242 srcaddr = (const void *)(srcobj->relocbase +
244 memcpy(dstaddr, srcaddr, size);
252 reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld)
254 const Elf_Rela *relalim;
255 const Elf_Rela *rela;
257 int bytes = obj->nchains * sizeof(SymCache);
261 * The dynamic loader may be called from a thread, we have
262 * limited amounts of stack available so we cannot use alloca().
264 if (obj != obj_rtld) {
265 cache = mmap(NULL, bytes, PROT_READ|PROT_WRITE, MAP_ANON,
267 if (cache == MAP_FAILED)
272 relalim = (const Elf_Rela *)((caddr_t)obj->rela + obj->relasize);
273 for (rela = obj->rela; rela < relalim; rela++) {
274 if (reloc_nonplt_object(obj, rela, cache) < 0)
280 munmap(cache, bytes);
285 reloc_nonplt_object(Obj_Entry *obj, const Elf_Rela *rela, SymCache *cache)
287 const Obj_Entry *defobj;
295 where = (Elf_Addr *)(obj->relocbase + rela->r_offset);
296 where32 = (Elf_Word *)where;
300 type = ELF64_R_TYPE_ID(rela->r_info);
301 if (type == R_SPARC_NONE)
304 /* We do JMP_SLOTs below */
305 if (type == R_SPARC_JMP_SLOT)
308 /* COPY relocs are also handled elsewhere */
309 if (type == R_SPARC_COPY)
313 * Note: R_SPARC_UA16 must be numerically largest relocation type.
315 if (type >= sizeof(reloc_target_bitmask) /
316 sizeof(*reloc_target_bitmask))
319 value = rela->r_addend;
322 * Handle relative relocs here, because we might not
323 * be able to access globals yet.
325 if (type == R_SPARC_RELATIVE) {
326 /* XXXX -- apparently we ignore the preexisting value */
327 *where = (Elf_Addr)(obj->relocbase + value);
332 * If we get here while relocating rtld itself, we will crash because
333 * a non-local variable is accessed.
335 if (RELOC_RESOLVE_SYMBOL(type)) {
337 /* Find the symbol */
338 def = find_symdef(ELF_R_SYM(rela->r_info), obj, &defobj,
343 /* Add in the symbol's absolute address */
344 value += (Elf_Addr)(defobj->relocbase + def->st_value);
347 if (type == R_SPARC_OLO10)
348 value = (value & 0x3ff) + ELF64_R_TYPE_DATA(rela->r_info);
350 if (RELOC_PC_RELATIVE(type))
351 value -= (Elf_Addr)where;
353 if (RELOC_BASE_RELATIVE(type)) {
355 * Note that even though sparcs use `Elf_rela' exclusively
356 * we still need the implicit memory addend in relocations
357 * referring to GOT entries. Undoubtedly, someone f*cked
358 * this up in the distant past, and now we're stuck with
359 * it in the name of compatibility for all eternity..
361 * In any case, the implicit and explicit should be mutually
362 * exclusive. We provide a check for that here.
364 /* XXXX -- apparently we ignore the preexisting value */
365 value += (Elf_Addr)(obj->relocbase);
368 mask = RELOC_VALUE_BITMASK(type);
369 value >>= RELOC_VALUE_RIGHTSHIFT(type);
372 if (RELOC_UNALIGNED(type)) {
373 /* Handle unaligned relocations. */
379 size = RELOC_TARGET_SIZE(type) / 8;
383 /* Read it in one byte at a time. */
384 for (i = 0; i < size; i++)
385 tmp = (tmp << 8) | ptr[i];
390 /* Write it back out. */
391 for (i = 0; i < size; i++)
392 ptr[i] = ((tmp >> ((size - i - 1) * 8)) & 0xff);
393 } else if (RELOC_TARGET_SIZE(type) > 32) {
405 reloc_plt(Obj_Entry *obj)
408 const Obj_Entry *defobj;
409 const Elf_Rela *relalim;
410 const Elf_Rela *rela;
415 relalim = (const Elf_Rela *)((char *)obj->pltrela + obj->pltrelasize);
416 for (rela = obj->pltrela; rela < relalim; rela++) {
417 if (rela->r_addend == 0)
419 assert(ELF64_R_TYPE_ID(rela->r_info) == R_SPARC_JMP_SLOT);
420 where = (Elf_Addr *)(obj->relocbase + rela->r_offset);
421 def = find_symdef(ELF_R_SYM(rela->r_info), obj, &defobj,
423 value = (Elf_Addr)(defobj->relocbase + def->st_value);
431 * Instruction templates:
433 #define BAA 0x10400000 /* ba,a %xcc, 0 */
434 #define SETHI 0x03000000 /* sethi %hi(0), %g1 */
435 #define JMP 0x81c06000 /* jmpl %g1+%lo(0), %g0 */
436 #define NOP 0x01000000 /* sethi %hi(0), %g0 */
437 #define OR 0x82806000 /* or %g1, 0, %g1 */
438 #define XOR 0x82c06000 /* xor %g1, 0, %g1 */
439 #define MOV71 0x8283a000 /* or %o7, 0, %g1 */
440 #define MOV17 0x9c806000 /* or %g1, 0, %o7 */
441 #define CALL 0x40000000 /* call 0 */
442 #define SLLX 0x8b407000 /* sllx %g1, 0, %g1 */
443 #define SETHIG5 0x0b000000 /* sethi %hi(0), %g5 */
444 #define ORG5 0x82804005 /* or %g1, %g5, %g1 */
447 /* %hi(v) with variable shift */
448 #define HIVAL(v, s) (((v) >> (s)) & 0x003fffff)
449 #define LOVAL(v) ((v) & 0x000003ff)
452 reloc_jmpslots(Obj_Entry *obj)
454 const Obj_Entry *defobj;
455 const Elf_Rela *relalim;
456 const Elf_Rela *rela;
461 relalim = (const Elf_Rela *)((char *)obj->pltrela + obj->pltrelasize);
462 for (rela = obj->pltrela; rela < relalim; rela++) {
463 assert(ELF64_R_TYPE_ID(rela->r_info) == R_SPARC_JMP_SLOT);
464 where = (Elf_Addr *)(obj->relocbase + rela->r_offset);
465 def = find_symdef(ELF_R_SYM(rela->r_info), obj, &defobj,
469 target = (Elf_Addr)(defobj->relocbase + def->st_value);
470 reloc_jmpslot(where, target, defobj, obj, (Elf_Rel *)rela);
472 obj->jmpslots_done = true;
477 reloc_jmpslot(Elf_Addr *wherep, Elf_Addr target, const Obj_Entry *obj,
478 const Obj_Entry *refobj, const Elf_Rel *rel)
480 const Elf_Rela *rela = (const Elf_Rela *)rel;
484 if (rela - refobj->pltrela < 32764) {
486 * At the PLT entry pointed at by `where', we now construct
487 * a direct transfer to the now fully resolved function
490 * A PLT entry is supposed to start by looking like this:
492 * sethi (. - .PLT0), %g1
501 * When we replace these entries we start from the second
502 * entry and do it in reverse order so the last thing we
503 * do is replace the branch. That allows us to change this
506 * We now need to find out how far we need to jump. We
507 * have a choice of several different relocation techniques
508 * which are increasingly expensive.
510 where = (Elf_Word *)wherep;
511 offset = ((Elf_Addr)where) - target;
512 if (offset <= (1L<<20) && offset >= -(1L<<20)) {
514 * We're within 1MB -- we can use a direct branch insn.
516 * We can generate this pattern:
518 * sethi %hi(. - .PLT0), %g1
528 where[1] = BAA | ((offset >> 2) &0x3fffff);
530 } else if (target >= 0 && target < (1L<<32)) {
532 * We're withing 32-bits of address zero.
534 * The resulting code in the jump slot is:
536 * sethi %hi(. - .PLT0), %g1
537 * sethi %hi(addr), %g1
546 where[2] = JMP | LOVAL(target);
548 where[1] = SETHI | HIVAL(target, 10);
550 } else if (target <= 0 && target > -(1L<<32)) {
552 * We're withing 32-bits of address -1.
554 * The resulting code in the jump slot is:
556 * sethi %hi(. - .PLT0), %g1
557 * sethi %hix(addr), %g1
558 * xor %g1, %lox(addr), %g1
568 where[2] = XOR | ((~target) & 0x00001fff);
570 where[1] = SETHI | HIVAL(~target, 10);
572 } else if (offset <= (1L<<32) && offset >= -((1L<<32) - 4)) {
574 * We're withing 32-bits -- we can use a direct call
577 * The resulting code in the jump slot is:
579 * sethi %hi(. - .PLT0), %g1
591 where[2] = CALL | ((offset >> 4) & 0x3fffffff);
595 } else if (offset >= 0 && offset < (1L<<44)) {
597 * We're withing 44 bits. We can generate this pattern:
599 * The resulting code in the jump slot is:
601 * sethi %hi(. - .PLT0), %g1
602 * sethi %h44(addr), %g1
603 * or %g1, %m44(addr), %g1
611 where[4] = JMP | LOVAL(offset);
613 where[3] = SLLX | 12;
615 where[2] = OR | (((offset) >> 12) & 0x00001fff);
617 where[1] = SETHI | HIVAL(offset, 22);
619 } else if (offset < 0 && offset > -(1L<<44)) {
621 * We're withing 44 bits. We can generate this pattern:
623 * The resulting code in the jump slot is:
625 * sethi %hi(. - .PLT0), %g1
626 * sethi %h44(-addr), %g1
627 * xor %g1, %m44(-addr), %g1
635 where[4] = JMP | LOVAL(offset);
637 where[3] = SLLX | 12;
639 where[2] = XOR | (((~offset) >> 12) & 0x00001fff);
641 where[1] = SETHI | HIVAL(~offset, 22);
645 * We need to load all 64-bits
647 * The resulting code in the jump slot is:
649 * sethi %hi(. - .PLT0), %g1
650 * sethi %hh(addr), %g1
651 * sethi %lm(addr), %g5
652 * or %g1, %hm(addr), %g1
659 where[6] = JMP | LOVAL(target);
663 where[4] = SLLX | 32;
665 where[3] = OR | LOVAL((target) >> 32);
667 where[2] = SETHIG5 | HIVAL(target, 10);
669 where[1] = SETHI | HIVAL(target, 42);
674 * This is a high PLT slot; the relocation offset specifies a
675 * pointer that needs to be frobbed; no actual code needs to
676 * be modified. The pointer to be calculated needs the addend
677 * added and the reference object relocation base subtraced.
679 *wherep = target + rela->r_addend -
680 (Elf_Addr)refobj->relocbase;
687 * Install rtld function call into this PLT slot.
689 #define SAVE 0x9de3bf50
690 #define SETHI_l0 0x21000000
691 #define SETHI_l1 0x23000000
692 #define OR_l0_l0 0xa0142000
693 #define SLLX_l0_32_l0 0xa12c3020
694 #define OR_l0_l1_l0 0xa0140011
695 #define JMPL_l0_o1 0x93c42000
696 #define MOV_g1_o0 0x90100001
699 init_pltgot(Obj_Entry *obj)
703 if (obj->pltgot != NULL) {
704 entry = (Elf_Word *)obj->pltgot;
705 install_plt(&entry[0], (Elf_Addr)_rtld_bind_start_0);
706 install_plt(&entry[8], (Elf_Addr)_rtld_bind_start_1);
707 obj->pltgot[8] = (Elf_Addr)obj;
712 install_plt(Elf_Word *pltgot, Elf_Addr proc)
716 pltgot[1] = SETHI_l0 | HIVAL(proc, 42);
718 pltgot[2] = SETHI_l1 | HIVAL(proc, 10);
720 pltgot[3] = OR_l0_l0 | LOVAL((proc) >> 32);
722 pltgot[4] = SLLX_l0_32_l0;
724 pltgot[5] = OR_l0_l1_l0;
726 pltgot[6] = JMPL_l0_o1 | LOVAL(proc);
728 pltgot[7] = MOV_g1_o0;
733 allocate_initial_tls(Obj_Entry *objs)
738 * Fix the size of the static TLS block by using the maximum
739 * offset allocated so far and adding a bit for dynamic modules to
742 tls_static_space = tls_last_offset + RTLD_STATIC_TLS_EXTRA;
743 tpval = allocate_tls(objs, NULL, 3*sizeof(Elf_Addr), sizeof(Elf_Addr));
744 __asm __volatile("mov %0, %%g7" : : "r" (tpval));
747 void *__tls_get_addr(tls_index *ti)
749 register Elf_Addr** tp __asm__("%g7");
751 return tls_get_addr_common(tp, ti->ti_module, ti->ti_offset);