]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - libexec/rtld-elf/mips/reloc.c
Update ELF Tool Chain to upstream r3520
[FreeBSD/FreeBSD.git] / libexec / rtld-elf / mips / reloc.c
1 /*      $NetBSD: mips_reloc.c,v 1.58 2010/01/14 11:57:06 skrll Exp $    */
2
3 /*
4  * Copyright 1997 Michael L. Hitch <mhitch@montana.edu>
5  * Portions copyright 2002 Charles M. Hannum <root@ihack.net>
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. The name of the author may not be used to endorse or promote products
17  *    derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
33
34 #include <sys/types.h>
35 #include <sys/stat.h>
36 #include <sys/endian.h>
37
38 #include <stdlib.h>
39 #include <string.h>
40 #include <inttypes.h>
41
42 #include <machine/sysarch.h>
43 #include <machine/tls.h>
44
45 #include "debug.h"
46 #include "rtld.h"
47
48 #ifdef __mips_n64
49 #define GOT1_MASK       0x8000000000000000UL
50 #else
51 #define GOT1_MASK       0x80000000UL
52 #endif
53
54 /*
55  * Determine if the second GOT entry is reserved for rtld or if it is
56  * the first "real" GOT entry.
57  *
58  * This must be a macro rather than a function so that
59  * _rtld_relocate_nonplt_self doesn't trigger a GOT invocation trying
60  * to use it before the local GOT entries in rtld are adjusted.
61  */
62 #ifdef __mips_n64
63 /* Old binutils uses the 32-bit GOT1 mask value for N64. */
64 #define GOT1_RESERVED_FOR_RTLD(got)                                     \
65         (((got)[1] == 0x80000000) || (got)[1] & GOT1_MASK)
66 #else
67 #define GOT1_RESERVED_FOR_RTLD(got)     ((got)[1] & GOT1_MASK)
68 #endif
69
70 void
71 init_pltgot(Obj_Entry *obj)
72 {
73         if (obj->pltgot != NULL) {
74                 obj->pltgot[0] = (Elf_Addr) &_rtld_bind_start;
75                 if (GOT1_RESERVED_FOR_RTLD(obj->pltgot))
76                         obj->pltgot[1] = (Elf_Addr) obj | GOT1_MASK;
77         }
78 }
79
80 int
81 do_copy_relocations(Obj_Entry *dstobj)
82 {
83         /* Do nothing */
84         return 0;
85 }
86
87 void _rtld_relocate_nonplt_self(Elf_Dyn *, Elf_Addr);
88
89 /*
90  * It is possible for the compiler to emit relocations for unaligned data.
91  * We handle this situation with these inlines.
92  */
93 #ifdef __mips_n64
94 /*
95  * ELF64 MIPS encodes the relocs uniquely.  The first 32-bits of info contain
96  * the symbol index.  The top 32-bits contain three relocation types encoded
97  * in big-endian integer with first relocation in LSB.  This means for little
98  * endian we have to byte swap that integer (r_type).
99  */
100 #define Elf_Sxword                      Elf64_Sxword
101 #define ELF_R_NXTTYPE_64_P(r_type)      ((((r_type) >> 8) & 0xff) == R_TYPE(64))
102 #if BYTE_ORDER == LITTLE_ENDIAN
103 #undef ELF_R_SYM
104 #undef ELF_R_TYPE
105 #define ELF_R_SYM(r_info)               ((r_info) & 0xffffffff)
106 #define ELF_R_TYPE(r_info)              bswap32((r_info) >> 32)
107 #endif
108 #else
109 #define ELF_R_NXTTYPE_64_P(r_type)      (0)
110 #define Elf_Sxword                      Elf32_Sword
111 #endif
112
113 static __inline Elf_Sxword
114 load_ptr(void *where, size_t len)
115 {
116         Elf_Sxword val;
117
118         if (__predict_true(((uintptr_t)where & (len - 1)) == 0)) {
119 #ifdef __mips_n64
120                 if (len == sizeof(Elf_Sxword))
121                         return *(Elf_Sxword *)where;
122 #endif
123                 return *(Elf_Sword *)where;
124         }
125
126         val = 0;
127 #if BYTE_ORDER == LITTLE_ENDIAN
128         (void)memcpy(&val, where, len);
129 #endif
130 #if BYTE_ORDER == BIG_ENDIAN
131         (void)memcpy((uint8_t *)((&val)+1) - len, where, len);
132 #endif
133         return (len == sizeof(Elf_Sxword)) ? val : (Elf_Sword)val;
134 }
135
136 static __inline void
137 store_ptr(void *where, Elf_Sxword val, size_t len)
138 {
139         if (__predict_true(((uintptr_t)where & (len - 1)) == 0)) {
140 #ifdef __mips_n64
141                 if (len == sizeof(Elf_Sxword)) {
142                         *(Elf_Sxword *)where = val;
143                         return;
144                 }
145 #endif
146                 *(Elf_Sword *)where = val;
147                 return;
148         }
149 #if BYTE_ORDER == LITTLE_ENDIAN
150         (void)memcpy(where, &val, len);
151 #endif
152 #if BYTE_ORDER == BIG_ENDIAN
153         (void)memcpy(where, (const uint8_t *)((&val)+1) - len, len);
154 #endif
155 }
156
157 void
158 _rtld_relocate_nonplt_self(Elf_Dyn *dynp, Elf_Addr relocbase)
159 {
160         const Elf_Rel *rel = NULL, *rellim;
161         Elf_Addr relsz = 0;
162         const Elf_Sym *symtab = NULL, *sym;
163         Elf_Addr *where;
164         Elf_Addr *got = NULL;
165         Elf_Word local_gotno = 0, symtabno = 0, gotsym = 0;
166         size_t i;
167
168         for (; dynp->d_tag != DT_NULL; dynp++) {
169                 switch (dynp->d_tag) {
170                 case DT_REL:
171                         rel = (const Elf_Rel *)(relocbase + dynp->d_un.d_ptr);
172                         break;
173                 case DT_RELSZ:
174                         relsz = dynp->d_un.d_val;
175                         break;
176                 case DT_SYMTAB:
177                         symtab = (const Elf_Sym *)(relocbase + dynp->d_un.d_ptr);
178                         break;
179                 case DT_PLTGOT:
180                         got = (Elf_Addr *)(relocbase + dynp->d_un.d_ptr);
181                         break;
182                 case DT_MIPS_LOCAL_GOTNO:
183                         local_gotno = dynp->d_un.d_val;
184                         break;
185                 case DT_MIPS_SYMTABNO:
186                         symtabno = dynp->d_un.d_val;
187                         break;
188                 case DT_MIPS_GOTSYM:
189                         gotsym = dynp->d_un.d_val;
190                         break;
191                 }
192         }
193
194         i = GOT1_RESERVED_FOR_RTLD(got) ? 2 : 1;
195         /* Relocate the local GOT entries */
196         got += i;
197         for (; i < local_gotno; i++) {
198                 *got++ += relocbase;
199         }
200
201         sym = symtab + gotsym;
202         /* Now do the global GOT entries */
203         for (i = gotsym; i < symtabno; i++) {
204                 *got = sym->st_value + relocbase;
205                 ++sym;
206                 ++got;
207         }
208
209         rellim = (const Elf_Rel *)((caddr_t)rel + relsz);
210         for (; rel < rellim; rel++) {
211                 Elf_Word r_symndx, r_type;
212
213                 where = (void *)(relocbase + rel->r_offset);
214
215                 r_symndx = ELF_R_SYM(rel->r_info);
216                 r_type = ELF_R_TYPE(rel->r_info);
217
218                 switch (r_type & 0xff) {
219                 case R_TYPE(REL32): {
220                         const size_t rlen =
221                             ELF_R_NXTTYPE_64_P(r_type)
222                                 ? sizeof(Elf_Sxword)
223                                 : sizeof(Elf_Sword);
224                         Elf_Sxword old = load_ptr(where, rlen);
225                         Elf_Sxword val = old;
226 #ifdef __mips_n64
227                         assert(r_type == R_TYPE(REL32)
228                             || r_type == (R_TYPE(REL32)|(R_TYPE(64) << 8)));
229 #endif
230                         assert(r_symndx < gotsym);
231                         sym = symtab + r_symndx;
232                         assert(ELF_ST_BIND(sym->st_info) == STB_LOCAL);
233                         val += relocbase;
234                         dbg("REL32/L(%p) %p -> %p in <self>",
235                             where, (void *)old, (void *)val);
236                         store_ptr(where, val, rlen);
237                         break;
238                 }
239
240                 case R_TYPE(GPREL32):
241                 case R_TYPE(NONE):
242                         break;
243
244
245                 default:
246                         abort();
247                         break;
248                 }
249         }
250 }
251
252 Elf_Addr
253 _mips_rtld_bind(Obj_Entry *obj, Elf_Size reloff)
254 {
255         Elf_Addr *got = obj->pltgot;
256         const Elf_Sym *def;
257         const Obj_Entry *defobj;
258         Elf_Addr *where;
259         Elf_Addr target;
260         RtldLockState lockstate;
261
262         rlock_acquire(rtld_bind_lock, &lockstate);
263         if (sigsetjmp(lockstate.env, 0) != 0)
264                 lock_upgrade(rtld_bind_lock, &lockstate);
265
266         where = &got[obj->local_gotno + reloff - obj->gotsym];
267         def = find_symdef(reloff, obj, &defobj, SYMLOOK_IN_PLT, NULL,
268            &lockstate);
269         if (def == NULL)
270                 rtld_die();
271
272         target = (Elf_Addr)(defobj->relocbase + def->st_value);
273         dbg("bind now/fixup at %s sym # %jd in %s --> was=%p new=%p",
274             obj->path,
275             (intmax_t)reloff, defobj->strtab + def->st_name, 
276             (void *)*where, (void *)target);
277         if (!ld_bind_not)
278                 *where = target;
279         lock_release(rtld_bind_lock, &lockstate);
280         return (Elf_Addr)target;
281 }
282
283 int
284 reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld, int flags,
285     RtldLockState *lockstate)
286 {
287         const Elf_Rel *rel;
288         const Elf_Rel *rellim;
289         Elf_Addr *got = obj->pltgot;
290         const Elf_Sym *sym, *def;
291         const Obj_Entry *defobj;
292         Elf_Word i;
293 #ifdef SUPPORT_OLD_BROKEN_LD
294         int broken;
295 #endif
296
297         /* The relocation for the dynamic loader has already been done. */
298         if (obj == obj_rtld)
299                 return (0);
300
301         if ((flags & SYMLOOK_IFUNC) != 0)
302                 /* XXX not implemented */
303                 return (0);
304
305 #ifdef SUPPORT_OLD_BROKEN_LD
306         broken = 0;
307         sym = obj->symtab;
308         for (i = 1; i < 12; i++)
309                 if (sym[i].st_info == ELF_ST_INFO(STB_LOCAL, STT_NOTYPE))
310                         broken = 1;
311         dbg("%s: broken=%d", obj->path, broken);
312 #endif
313
314         i = GOT1_RESERVED_FOR_RTLD(got) ? 2 : 1;
315
316         /* Relocate the local GOT entries */
317         got += i;
318         dbg("got:%p for %d entries adding %p",
319             got, obj->local_gotno, obj->relocbase);
320         for (; i < obj->local_gotno; i++) {
321                 *got += (Elf_Addr)obj->relocbase;
322                 got++;
323         }
324         sym = obj->symtab + obj->gotsym;
325
326         dbg("got:%p for %d entries",
327             got, obj->symtabno);
328         /* Now do the global GOT entries */
329         for (i = obj->gotsym; i < obj->symtabno; i++) {
330                 dbg(" doing got %d sym %p (%s, %lx)", i - obj->gotsym, sym,
331                     sym->st_name + obj->strtab, (u_long) *got);
332
333 #ifdef SUPPORT_OLD_BROKEN_LD
334                 if (ELF_ST_TYPE(sym->st_info) == STT_FUNC &&
335                     broken && sym->st_shndx == SHN_UNDEF) {
336                         /*
337                          * XXX DANGER WILL ROBINSON!
338                          * You might think this is stupid, as it intentionally
339                          * defeats lazy binding -- and you'd be right.
340                          * Unfortunately, for lazy binding to work right, we
341                          * need to a way to force the GOT slots used for
342                          * function pointers to be resolved immediately.  This
343                          * is supposed to be done automatically by the linker,
344                          * by not outputting a PLT slot and setting st_value
345                          * to 0 if there are non-PLT references, but older
346                          * versions of GNU ld do not do this.
347                          */
348                         def = find_symdef(i, obj, &defobj, flags, NULL,
349                             lockstate);
350                         if (def == NULL)
351                                 return -1;
352                         *got = def->st_value + (Elf_Addr)defobj->relocbase;
353                 } else
354 #endif
355                 if (ELF_ST_TYPE(sym->st_info) == STT_FUNC &&
356                     sym->st_value != 0 && sym->st_shndx == SHN_UNDEF) {
357                         /*
358                          * If there are non-PLT references to the function,
359                          * st_value should be 0, forcing us to resolve the
360                          * address immediately.
361                          *
362                          * XXX DANGER WILL ROBINSON!
363                          * The linker is not outputting PLT slots for calls to
364                          * functions that are defined in the same shared
365                          * library.  This is a bug, because it can screw up
366                          * link ordering rules if the symbol is defined in
367                          * more than one module.  For now, if there is a
368                          * definition, we fail the test above and force a full
369                          * symbol lookup.  This means that all intra-module
370                          * calls are bound immediately.  - mycroft, 2003/09/24
371                          */
372                         *got = sym->st_value + (Elf_Addr)obj->relocbase;
373                         if ((Elf_Addr)(*got) == (Elf_Addr)obj->relocbase) {
374                                 dbg("Warning2, i:%d maps to relocbase address:%p",
375                                     i, obj->relocbase);
376                         }
377
378                 } else if (sym->st_info == ELF_ST_INFO(STB_GLOBAL, STT_SECTION)) {
379                         /* Symbols with index SHN_ABS are not relocated. */
380                         if (sym->st_shndx != SHN_ABS) {
381                                 *got = sym->st_value +
382                                     (Elf_Addr)obj->relocbase;
383                                 if ((Elf_Addr)(*got) == (Elf_Addr)obj->relocbase) {
384                                         dbg("Warning3, i:%d maps to relocbase address:%p",
385                                             i, obj->relocbase);
386                                 }
387                         }
388                 } else {
389                         /* TODO: add cache here */
390                         def = find_symdef(i, obj, &defobj, flags, NULL,
391                             lockstate);
392                         if (def == NULL) {
393                                 dbg("Warning4, can't find symbole %d", i);
394                                 return -1;
395                         }
396                         *got = def->st_value + (Elf_Addr)defobj->relocbase;
397                         if ((Elf_Addr)(*got) == (Elf_Addr)obj->relocbase) {
398                                 dbg("Warning4, i:%d maps to relocbase address:%p",
399                                     i, obj->relocbase);
400                                 dbg("via first obj symbol %s",
401                                     obj->strtab + obj->symtab[i].st_name);
402                                 dbg("found in obj %p:%s",
403                                     defobj, defobj->path);
404                         }
405                 }
406
407                 dbg("  --> now %lx", (u_long) *got);
408                 ++sym;
409                 ++got;
410         }
411
412         got = obj->pltgot;
413         rellim = (const Elf_Rel *)((caddr_t)obj->rel + obj->relsize);
414         for (rel = obj->rel; rel < rellim; rel++) {
415                 Elf_Word        r_symndx, r_type;
416                 void            *where;
417
418                 where = obj->relocbase + rel->r_offset;
419                 r_symndx = ELF_R_SYM(rel->r_info);
420                 r_type = ELF_R_TYPE(rel->r_info);
421
422                 switch (r_type & 0xff) {
423                 case R_TYPE(NONE):
424                         break;
425
426                 case R_TYPE(REL32): {
427                         /* 32-bit PC-relative reference */
428                         const size_t rlen =
429                             ELF_R_NXTTYPE_64_P(r_type)
430                                 ? sizeof(Elf_Sxword)
431                                 : sizeof(Elf_Sword);
432                         Elf_Sxword old = load_ptr(where, rlen);
433                         Elf_Sxword val = old;
434
435                         def = obj->symtab + r_symndx;
436
437                         if (r_symndx >= obj->gotsym) {
438                                 val += got[obj->local_gotno + r_symndx - obj->gotsym];
439                                 dbg("REL32/G(%p) %p --> %p (%s) in %s",
440                                     where, (void *)old, (void *)val,
441                                     obj->strtab + def->st_name,
442                                     obj->path);
443                         } else {
444                                 /*
445                                  * XXX: ABI DIFFERENCE!
446                                  *
447                                  * Old NetBSD binutils would generate shared
448                                  * libs with section-relative relocations being
449                                  * already adjusted for the start address of
450                                  * the section.
451                                  *
452                                  * New binutils, OTOH, generate shared libs
453                                  * with the same relocations being based at
454                                  * zero, so we need to add in the start address
455                                  * of the section.
456                                  *
457                                  * --rkb, Oct 6, 2001
458                                  */
459
460                                 if (def->st_info ==
461                                     ELF_ST_INFO(STB_LOCAL, STT_SECTION)
462 #ifdef SUPPORT_OLD_BROKEN_LD
463                                     && !broken
464 #endif
465                                     )
466                                         val += (Elf_Addr)def->st_value;
467
468                                 val += (Elf_Addr)obj->relocbase;
469
470                                 dbg("REL32/L(%p) %p -> %p (%s) in %s",
471                                     where, (void *)old, (void *)val,
472                                     obj->strtab + def->st_name, obj->path);
473                         }
474                         store_ptr(where, val, rlen);
475                         break;
476                 }
477
478 #ifdef __mips_n64
479                 case R_TYPE(TLS_DTPMOD64):
480 #else
481                 case R_TYPE(TLS_DTPMOD32): 
482 #endif
483                 {
484
485                         const size_t rlen = sizeof(Elf_Addr);
486                         Elf_Addr old = load_ptr(where, rlen);
487                         Elf_Addr val = old;
488
489                         def = find_symdef(r_symndx, obj, &defobj, flags, NULL,
490                                 lockstate);
491                         if (def == NULL)
492                                 return -1;
493
494                         val += (Elf_Addr)defobj->tlsindex;
495
496                         store_ptr(where, val, rlen);
497                         dbg("DTPMOD %s in %s %p --> %p in %s",
498                             obj->strtab + obj->symtab[r_symndx].st_name,
499                             obj->path, (void *)old, (void*)val, defobj->path);
500                         break;
501                 }
502
503 #ifdef __mips_n64
504                 case R_TYPE(TLS_DTPREL64):
505 #else
506                 case R_TYPE(TLS_DTPREL32):
507 #endif
508                 {
509                         const size_t rlen = sizeof(Elf_Addr);
510                         Elf_Addr old = load_ptr(where, rlen);
511                         Elf_Addr val = old;
512
513                         def = find_symdef(r_symndx, obj, &defobj, flags, NULL,
514                                 lockstate);
515                         if (def == NULL)
516                                 return -1;
517
518                         if (!defobj->tls_done && allocate_tls_offset(obj))
519                                 return -1;
520
521                         val += (Elf_Addr)def->st_value - TLS_DTP_OFFSET;
522                         store_ptr(where, val, rlen);
523
524                         dbg("DTPREL %s in %s %p --> %p in %s",
525                             obj->strtab + obj->symtab[r_symndx].st_name,
526                             obj->path, (void*)old, (void *)val, defobj->path);
527                         break;
528                 }
529
530 #ifdef __mips_n64
531                 case R_TYPE(TLS_TPREL64):
532 #else
533                 case R_TYPE(TLS_TPREL32):
534 #endif
535                 {
536                         const size_t rlen = sizeof(Elf_Addr);
537                         Elf_Addr old = load_ptr(where, rlen);
538                         Elf_Addr val = old;
539
540                         def = find_symdef(r_symndx, obj, &defobj, flags, NULL,
541                                 lockstate);
542
543                         if (def == NULL)
544                                 return -1;
545
546                         if (!defobj->tls_done && allocate_tls_offset(obj))
547                                 return -1;
548
549                         val += (Elf_Addr)(def->st_value + defobj->tlsoffset
550                             - TLS_TP_OFFSET - TLS_TCB_SIZE);
551                         store_ptr(where, val, rlen);
552
553                         dbg("TPREL %s in %s %p --> %p in %s",
554                             obj->strtab + obj->symtab[r_symndx].st_name,
555                             obj->path, (void*)old, (void *)val, defobj->path);
556                         break;
557                 }
558
559
560
561                 default:
562                         dbg("sym = %lu, type = %lu, offset = %p, "
563                             "contents = %p, symbol = %s",
564                             (u_long)r_symndx, (u_long)ELF_R_TYPE(rel->r_info),
565                             (void *)rel->r_offset,
566                             (void *)load_ptr(where, sizeof(Elf_Sword)),
567                             obj->strtab + obj->symtab[r_symndx].st_name);
568                         _rtld_error("%s: Unsupported relocation type %ld "
569                             "in non-PLT relocations",
570                             obj->path, (u_long) ELF_R_TYPE(rel->r_info));
571                         return -1;
572                 }
573         }
574
575         return 0;
576 }
577
578 /*
579  *  Process the PLT relocations.
580  */
581 int
582 reloc_plt(Obj_Entry *obj)
583 {
584 #if 0
585         const Elf_Rel *rellim;
586         const Elf_Rel *rel;
587                 
588         dbg("reloc_plt obj:%p pltrel:%p sz:%s", obj, obj->pltrel, (int)obj->pltrelsize);
589         dbg("gottable %p num syms:%s", obj->pltgot, obj->symtabno );
590         dbg("*****************************************************");
591         rellim = (const Elf_Rel *)((char *)obj->pltrel +
592             obj->pltrelsize);
593         for (rel = obj->pltrel;  rel < rellim;  rel++) {
594                 Elf_Addr *where;
595                 where = (Elf_Addr *)(obj->relocbase + rel->r_offset);
596                 *where += (Elf_Addr )obj->relocbase;
597         }
598
599 #endif
600         /* PLT fixups were done above in the GOT relocation. */
601         return (0);
602 }
603
604 /*
605  * LD_BIND_NOW was set - force relocation for all jump slots
606  */
607 int
608 reloc_jmpslots(Obj_Entry *obj, int flags, RtldLockState *lockstate)
609 {
610         /* Do nothing */
611         obj->jmpslots_done = true;
612         
613         return (0);
614 }
615
616 int
617 reloc_iresolve(Obj_Entry *obj, struct Struct_RtldLockState *lockstate)
618 {
619
620         /* XXX not implemented */
621         return (0);
622 }
623
624 int
625 reloc_gnu_ifunc(Obj_Entry *obj, int flags,
626     struct Struct_RtldLockState *lockstate)
627 {
628
629         /* XXX not implemented */
630         return (0);
631 }
632
633 Elf_Addr
634 reloc_jmpslot(Elf_Addr *where, Elf_Addr target, const Obj_Entry *defobj,
635                 const Obj_Entry *obj, const Elf_Rel *rel)
636 {
637
638         /* Do nothing */
639
640         return target;
641 }
642
643 void
644 ifunc_init(Elf_Auxinfo aux_info[__min_size(AT_COUNT)] __unused)
645 {
646 }
647
648 void
649 allocate_initial_tls(Obj_Entry *objs)
650 {
651         char *tls;
652         
653         /*
654          * Fix the size of the static TLS block by using the maximum
655          * offset allocated so far and adding a bit for dynamic modules to
656          * use.
657          */
658         tls_static_space = tls_last_offset + tls_last_size + RTLD_STATIC_TLS_EXTRA;
659
660         tls = (char *) allocate_tls(objs, NULL, TLS_TCB_SIZE, 8);
661
662         sysarch(MIPS_SET_TLS, tls);
663 }
664
665 #ifdef __mips_n64
666 void *
667 _mips_get_tls(void)
668 {
669         uint64_t _rv;
670
671         __asm__ __volatile__ (
672             ".set\tpush\n\t"
673             ".set\tmips64r2\n\t"
674             "rdhwr\t%0, $29\n\t"
675             ".set\tpop"
676             : "=r" (_rv));
677         /*
678          * XXXSS See 'git show c6be4f4d2d1b71c04de5d3bbb6933ce2dbcdb317'
679          *
680          * Remove the offset since this really a request to get the TLS
681          * pointer via sysarch() (in theory).  Of course, this may go away
682          * once the TLS code is rewritten.
683          */
684         _rv = _rv - TLS_TP_OFFSET - TLS_TCB_SIZE;
685
686         return (void *)_rv;
687 }
688
689 #else /* mips 32 */
690
691 void *
692 _mips_get_tls(void)
693 {
694         uint32_t _rv;
695
696         __asm__ __volatile__ (
697             ".set\tpush\n\t"
698             ".set\tmips32r2\n\t"
699             "rdhwr\t%0, $29\n\t"
700             ".set\tpop"
701             : "=r" (_rv));
702         /*
703          * XXXSS See 'git show c6be4f4d2d1b71c04de5d3bbb6933ce2dbcdb317'
704          *
705          * Remove the offset since this really a request to get the TLS
706          * pointer via sysarch() (in theory).  Of course, this may go away
707          * once the TLS code is rewritten.
708          */
709         _rv = _rv - TLS_TP_OFFSET - TLS_TCB_SIZE;
710
711         return (void *)_rv;
712 }
713 #endif /* ! __mips_n64 */
714
715 void *
716 __tls_get_addr(tls_index* ti)
717 {
718         Elf_Addr** tls;
719         char *p;
720
721 #ifdef TLS_USE_SYSARCH
722         sysarch(MIPS_GET_TLS, &tls);
723 #else
724         tls = _mips_get_tls();
725 #endif
726
727         p = tls_get_addr_common(tls, ti->ti_module, ti->ti_offset + TLS_DTP_OFFSET);
728
729         return (p);
730 }