]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/mips/dl-machine.h
* sysdeps/mips/dl-machine.h (ELF_MACHINE_NO_RELA): Delete.
[thirdparty/glibc.git] / sysdeps / mips / dl-machine.h
1 /* Machine-dependent ELF dynamic relocation inline functions. MIPS version.
2 Copyright (C) 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007
3 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
5 Contributed by Kazumoto Kojima <kkojima@info.kanagawa-u.ac.jp>.
6
7 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
11
12 The GNU C Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library; if not, write to the Free
19 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 02111-1307 USA. */
21
22 /* FIXME: Profiling of shared libraries is not implemented yet. */
23 #ifndef dl_machine_h
24 #define dl_machine_h
25
26 #define ELF_MACHINE_NAME "MIPS"
27
28 #define ELF_MACHINE_NO_PLT
29
30 #include <entry.h>
31
32 #ifndef ENTRY_POINT
33 #error ENTRY_POINT needs to be defined for MIPS.
34 #endif
35
36 #include <sgidefs.h>
37 #include <sys/asm.h>
38 #include <dl-tls.h>
39
40 /* The offset of gp from GOT might be system-dependent. It's set by
41 ld. The same value is also */
42 #define OFFSET_GP_GOT 0x7ff0
43
44 #ifndef _RTLD_PROLOGUE
45 # define _RTLD_PROLOGUE(entry) \
46 ".globl\t" __STRING(entry) "\n\t" \
47 ".ent\t" __STRING(entry) "\n\t" \
48 ".type\t" __STRING(entry) ", @function\n" \
49 __STRING(entry) ":\n\t"
50 #endif
51
52 #ifndef _RTLD_EPILOGUE
53 # define _RTLD_EPILOGUE(entry) \
54 ".end\t" __STRING(entry) "\n\t" \
55 ".size\t" __STRING(entry) ", . - " __STRING(entry) "\n\t"
56 #endif
57
58 /* A reloc type used for ld.so cmdline arg lookups to reject PLT entries.
59 This makes no sense on MIPS but we have to define this to R_MIPS_REL32
60 to avoid the asserts in dl-lookup.c from blowing. */
61 #define ELF_MACHINE_JMP_SLOT R_MIPS_REL32
62 #define elf_machine_type_class(type) ELF_RTYPE_CLASS_PLT
63
64 /* Translate a processor specific dynamic tag to the index
65 in l_info array. */
66 #define DT_MIPS(x) (DT_MIPS_##x - DT_LOPROC + DT_NUM)
67
68 /* If there is a DT_MIPS_RLD_MAP entry in the dynamic section, fill it in
69 with the run-time address of the r_debug structure */
70 #define ELF_MACHINE_DEBUG_SETUP(l,r) \
71 do { if ((l)->l_info[DT_MIPS (RLD_MAP)]) \
72 *(ElfW(Addr) *)((l)->l_info[DT_MIPS (RLD_MAP)]->d_un.d_ptr) = \
73 (ElfW(Addr)) (r); \
74 } while (0)
75
76 /* Return nonzero iff ELF header is compatible with the running host. */
77 static inline int __attribute_used__
78 elf_machine_matches_host (const ElfW(Ehdr) *ehdr)
79 {
80 #if _MIPS_SIM == _ABIO32 || _MIPS_SIM == _ABIN32
81 /* Don't link o32 and n32 together. */
82 if (((ehdr->e_flags & EF_MIPS_ABI2) != 0) != (_MIPS_SIM == _ABIN32))
83 return 0;
84 #endif
85
86 switch (ehdr->e_machine)
87 {
88 case EM_MIPS:
89 case EM_MIPS_RS3_LE:
90 return 1;
91 default:
92 return 0;
93 }
94 }
95
96 static inline ElfW(Addr) *
97 elf_mips_got_from_gpreg (ElfW(Addr) gpreg)
98 {
99 /* FIXME: the offset of gp from GOT may be system-dependent. */
100 return (ElfW(Addr) *) (gpreg - OFFSET_GP_GOT);
101 }
102
103 /* Return the link-time address of _DYNAMIC. Conveniently, this is the
104 first element of the GOT. This must be inlined in a function which
105 uses global data. We assume its $gp points to the primary GOT. */
106 static inline ElfW(Addr)
107 elf_machine_dynamic (void)
108 {
109 register ElfW(Addr) gp __asm__ ("$28");
110 return *elf_mips_got_from_gpreg (gp);
111 }
112
113 #define STRINGXP(X) __STRING(X)
114 #define STRINGXV(X) STRINGV_(X)
115 #define STRINGV_(...) # __VA_ARGS__
116
117 /* Return the run-time load address of the shared object. */
118 static inline ElfW(Addr)
119 elf_machine_load_address (void)
120 {
121 ElfW(Addr) addr;
122 asm (" .set noreorder\n"
123 " " STRINGXP (PTR_LA) " %0, 0f\n"
124 " bltzal $0, 0f\n"
125 " nop\n"
126 "0: " STRINGXP (PTR_SUBU) " %0, $31, %0\n"
127 " .set reorder\n"
128 : "=r" (addr)
129 : /* No inputs */
130 : "$31");
131 return addr;
132 }
133
134 /* The MSB of got[1] of a gnu object is set to identify gnu objects. */
135 #if _MIPS_SIM == _ABI64
136 # define ELF_MIPS_GNU_GOT1_MASK 0x8000000000000000L
137 #else
138 # define ELF_MIPS_GNU_GOT1_MASK 0x80000000L
139 #endif
140
141 /* We can't rely on elf_machine_got_rel because _dl_object_relocation_scope
142 fiddles with global data. */
143 #define ELF_MACHINE_BEFORE_RTLD_RELOC(dynamic_info) \
144 do { \
145 struct link_map *map = &bootstrap_map; \
146 ElfW(Sym) *sym; \
147 ElfW(Addr) *got; \
148 int i, n; \
149 \
150 got = (ElfW(Addr) *) D_PTR (map, l_info[DT_PLTGOT]); \
151 \
152 if (__builtin_expect (map->l_addr == 0, 1)) \
153 break; \
154 \
155 /* got[0] is reserved. got[1] is also reserved for the dynamic object \
156 generated by gnu ld. Skip these reserved entries from \
157 relocation. */ \
158 i = (got[1] & ELF_MIPS_GNU_GOT1_MASK)? 2 : 1; \
159 n = map->l_info[DT_MIPS (LOCAL_GOTNO)]->d_un.d_val; \
160 \
161 /* Add the run-time displacement to all local got entries. */ \
162 while (i < n) \
163 got[i++] += map->l_addr; \
164 \
165 /* Handle global got entries. */ \
166 got += n; \
167 sym = (ElfW(Sym) *) D_PTR(map, l_info[DT_SYMTAB]) \
168 + map->l_info[DT_MIPS (GOTSYM)]->d_un.d_val; \
169 i = (map->l_info[DT_MIPS (SYMTABNO)]->d_un.d_val \
170 - map->l_info[DT_MIPS (GOTSYM)]->d_un.d_val); \
171 \
172 while (i--) \
173 { \
174 if (sym->st_shndx == SHN_UNDEF || sym->st_shndx == SHN_COMMON) \
175 *got = map->l_addr + sym->st_value; \
176 else if (ELFW(ST_TYPE) (sym->st_info) == STT_FUNC \
177 && *got != sym->st_value) \
178 *got += map->l_addr; \
179 else if (ELFW(ST_TYPE) (sym->st_info) == STT_SECTION) \
180 { \
181 if (sym->st_other == 0) \
182 *got += map->l_addr; \
183 } \
184 else \
185 *got = map->l_addr + sym->st_value; \
186 \
187 got++; \
188 sym++; \
189 } \
190 } while(0)
191
192
193 /* Mask identifying addresses reserved for the user program,
194 where the dynamic linker should not map anything. */
195 #define ELF_MACHINE_USER_ADDRESS_MASK 0x80000000UL
196
197
198 /* Initial entry point code for the dynamic linker.
199 The C function `_dl_start' is the real entry point;
200 its return value is the user program's entry point.
201 Note how we have to be careful about two things:
202
203 1) That we allocate a minimal stack of 24 bytes for
204 every function call, the MIPS ABI states that even
205 if all arguments are passed in registers the procedure
206 called can use the 16 byte area pointed to by $sp
207 when it is called to store away the arguments passed
208 to it.
209
210 2) That under Linux the entry is named __start
211 and not just plain _start. */
212
213 #define RTLD_START asm (\
214 ".text\n\
215 " _RTLD_PROLOGUE(ENTRY_POINT) "\
216 " STRINGXV(SETUP_GPX($25)) "\n\
217 " STRINGXV(SETUP_GPX64($18,$25)) "\n\
218 # i386 ABI book says that the first entry of GOT holds\n\
219 # the address of the dynamic structure. Though MIPS ABI\n\
220 # doesn't say nothing about this, I emulate this here.\n\
221 " STRINGXP(PTR_LA) " $4, _DYNAMIC\n\
222 # Subtract OFFSET_GP_GOT\n\
223 " STRINGXP(PTR_S) " $4, -0x7ff0($28)\n\
224 move $4, $29\n\
225 " STRINGXP(PTR_SUBIU) " $29, 16\n\
226 \n\
227 " STRINGXP(PTR_LA) " $8, .Lcoff\n\
228 bltzal $8, .Lcoff\n\
229 .Lcoff: " STRINGXP(PTR_SUBU) " $8, $31, $8\n\
230 \n\
231 " STRINGXP(PTR_LA) " $25, _dl_start\n\
232 " STRINGXP(PTR_ADDU) " $25, $8\n\
233 jalr $25\n\
234 \n\
235 " STRINGXP(PTR_ADDIU) " $29, 16\n\
236 # Get the value of label '_dl_start_user' in t9 ($25).\n\
237 " STRINGXP(PTR_LA) " $25, _dl_start_user\n\
238 " _RTLD_EPILOGUE(ENTRY_POINT) "\
239 \n\
240 \n\
241 " _RTLD_PROLOGUE(_dl_start_user) "\
242 " STRINGXP(SETUP_GP) "\n\
243 " STRINGXV(SETUP_GP64($18,_dl_start_user)) "\n\
244 move $16, $28\n\
245 # Save the user entry point address in a saved register.\n\
246 move $17, $2\n\
247 # See if we were run as a command with the executable file\n\
248 # name as an extra leading argument.\n\
249 lw $2, _dl_skip_args\n\
250 beq $2, $0, 1f\n\
251 # Load the original argument count.\n\
252 " STRINGXP(PTR_L) " $4, 0($29)\n\
253 # Subtract _dl_skip_args from it.\n\
254 subu $4, $2\n\
255 # Adjust the stack pointer to skip _dl_skip_args words.\n\
256 sll $2, " STRINGXP (PTRLOG) "\n\
257 " STRINGXP(PTR_ADDU) " $29, $2\n\
258 # Save back the modified argument count.\n\
259 " STRINGXP(PTR_S) " $4, 0($29)\n\
260 1: # Call _dl_init (struct link_map *main_map, int argc, char **argv, char **env) \n\
261 " STRINGXP(PTR_L) " $4, _rtld_local\n\
262 " STRINGXP(PTR_L) /* or lw??? fixme */ " $5, 0($29)\n\
263 " STRINGXP(PTR_LA) " $6, " STRINGXP (PTRSIZE) "($29)\n\
264 sll $7, $5, " STRINGXP (PTRLOG) "\n\
265 " STRINGXP(PTR_ADDU) " $7, $7, $6\n\
266 " STRINGXP(PTR_ADDU) " $7, $7, " STRINGXP (PTRSIZE) " \n\
267 # Make sure the stack pointer is aligned for _dl_init_internal.\n\
268 and $2, $29, -2 * " STRINGXP(SZREG) "\n\
269 " STRINGXP(PTR_S) " $29, -" STRINGXP(SZREG) "($2)\n\
270 " STRINGXP(PTR_SUBIU) " $29, $2, 32\n\
271 " STRINGXP(SAVE_GP(16)) "\n\
272 # Call the function to run the initializers.\n\
273 jal _dl_init_internal\n\
274 # Restore the stack pointer for _start.\n\
275 " STRINGXP(PTR_L) " $29, 32-" STRINGXP(SZREG) "($29)\n\
276 # Pass our finalizer function to the user in $2 as per ELF ABI.\n\
277 " STRINGXP(PTR_LA) " $2, _dl_fini\n\
278 # Jump to the user entry point.\n\
279 move $25, $17\n\
280 jr $25\n\t"\
281 _RTLD_EPILOGUE(_dl_start_user)\
282 ".previous"\
283 );
284
285 /* Names of the architecture-specific auditing callback functions. */
286 # if _MIPS_SIM == _ABIO32
287 # define ARCH_LA_PLTENTER mips_o32_gnu_pltenter
288 # define ARCH_LA_PLTEXIT mips_o32_gnu_pltexit
289 # elif _MIPS_SIM == _ABIN32
290 # define ARCH_LA_PLTENTER mips_n32_gnu_pltenter
291 # define ARCH_LA_PLTEXIT mips_n32_gnu_pltexit
292 # else
293 # define ARCH_LA_PLTENTER mips_n64_gnu_pltenter
294 # define ARCH_LA_PLTEXIT mips_n64_gnu_pltexit
295 # endif
296
297 #endif /* !dl_machine_h */
298
299 #ifdef RESOLVE_MAP
300
301 /* Perform a relocation described by R_INFO at the location pointed to
302 by RELOC_ADDR. SYM is the relocation symbol specified by R_INFO and
303 MAP is the object containing the reloc. */
304
305 auto inline void
306 __attribute__ ((always_inline))
307 elf_machine_reloc (struct link_map *map, ElfW(Word) r_info,
308 const ElfW(Sym) *sym, const struct r_found_version *version,
309 void *reloc_addr, ElfW(Addr) r_addend, int inplace_p)
310 {
311 const unsigned long int r_type = ELFW(R_TYPE) (r_info);
312 ElfW(Addr) *addr_field = (ElfW(Addr) *) reloc_addr;
313
314 #if !defined RTLD_BOOTSTRAP && !defined SHARED
315 /* This is defined in rtld.c, but nowhere in the static libc.a;
316 make the reference weak so static programs can still link. This
317 declaration cannot be done when compiling rtld.c (i.e. #ifdef
318 RTLD_BOOTSTRAP) because rtld.c contains the common defn for
319 _dl_rtld_map, which is incompatible with a weak decl in the same
320 file. */
321 weak_extern (GL(dl_rtld_map));
322 #endif
323
324 switch (r_type)
325 {
326 #if defined (USE_TLS) && !defined (RTLD_BOOTSTRAP)
327 # if _MIPS_SIM == _ABI64
328 case R_MIPS_TLS_DTPMOD64:
329 case R_MIPS_TLS_DTPREL64:
330 case R_MIPS_TLS_TPREL64:
331 # else
332 case R_MIPS_TLS_DTPMOD32:
333 case R_MIPS_TLS_DTPREL32:
334 case R_MIPS_TLS_TPREL32:
335 # endif
336 {
337 struct link_map *sym_map = RESOLVE_MAP (&sym, version, r_type);
338
339 switch (r_type)
340 {
341 case R_MIPS_TLS_DTPMOD64:
342 case R_MIPS_TLS_DTPMOD32:
343 if (sym_map)
344 *addr_field = sym_map->l_tls_modid;
345 break;
346
347 case R_MIPS_TLS_DTPREL64:
348 case R_MIPS_TLS_DTPREL32:
349 if (sym)
350 {
351 if (inplace_p)
352 r_addend = *addr_field;
353 *addr_field = r_addend + TLS_DTPREL_VALUE (sym);
354 }
355 break;
356
357 case R_MIPS_TLS_TPREL32:
358 case R_MIPS_TLS_TPREL64:
359 if (sym)
360 {
361 CHECK_STATIC_TLS (map, sym_map);
362 if (inplace_p)
363 r_addend = *addr_field;
364 *addr_field = r_addend + TLS_TPREL_VALUE (sym_map, sym);
365 }
366 break;
367 }
368
369 break;
370 }
371 #endif
372
373 #if _MIPS_SIM == _ABI64
374 case (R_MIPS_64 << 8) | R_MIPS_REL32:
375 #else
376 case R_MIPS_REL32:
377 #endif
378 {
379 int symidx = ELFW(R_SYM) (r_info);
380 ElfW(Addr) reloc_value;
381
382 if (inplace_p)
383 /* Support relocations on mis-aligned offsets. */
384 __builtin_memcpy (&reloc_value, reloc_addr, sizeof (reloc_value));
385 else
386 reloc_value = r_addend;
387
388 if (symidx)
389 {
390 const ElfW(Word) gotsym
391 = (const ElfW(Word)) map->l_info[DT_MIPS (GOTSYM)]->d_un.d_val;
392
393 if ((ElfW(Word))symidx < gotsym)
394 {
395 /* This wouldn't work for a symbol imported from other
396 libraries for which there's no GOT entry, but MIPS
397 requires every symbol referenced in a dynamic
398 relocation to have a GOT entry in the primary GOT,
399 so we only get here for locally-defined symbols.
400 For section symbols, we should *NOT* be adding
401 sym->st_value (per the definition of the meaning of
402 S in reloc expressions in the ELF64 MIPS ABI),
403 since it should have already been added to
404 reloc_value by the linker, but older versions of
405 GNU ld didn't add it, and newer versions don't emit
406 useless relocations to section symbols any more, so
407 it is safe to keep on adding sym->st_value, even
408 though it's not ABI compliant. Some day we should
409 bite the bullet and stop doing this. */
410 #ifndef RTLD_BOOTSTRAP
411 if (map != &GL(dl_rtld_map))
412 #endif
413 reloc_value += sym->st_value + map->l_addr;
414 }
415 else
416 {
417 #ifndef RTLD_BOOTSTRAP
418 const ElfW(Addr) *got
419 = (const ElfW(Addr) *) D_PTR (map, l_info[DT_PLTGOT]);
420 const ElfW(Word) local_gotno
421 = (const ElfW(Word))
422 map->l_info[DT_MIPS (LOCAL_GOTNO)]->d_un.d_val;
423
424 reloc_value += got[symidx + local_gotno - gotsym];
425 #endif
426 }
427 }
428 else
429 #ifndef RTLD_BOOTSTRAP
430 if (map != &GL(dl_rtld_map))
431 #endif
432 reloc_value += map->l_addr;
433
434 __builtin_memcpy (reloc_addr, &reloc_value, sizeof (reloc_value));
435 }
436 break;
437 #ifndef RTLD_BOOTSTRAP
438 #if _MIPS_SIM == _ABI64
439 case (R_MIPS_64 << 8) | R_MIPS_GLOB_DAT:
440 #else
441 case R_MIPS_GLOB_DAT:
442 #endif
443 {
444 int symidx = ELFW(R_SYM) (r_info);
445 const ElfW(Word) gotsym
446 = (const ElfW(Word)) map->l_info[DT_MIPS (GOTSYM)]->d_un.d_val;
447
448 if (__builtin_expect ((ElfW(Word)) symidx >= gotsym, 1))
449 {
450 const ElfW(Addr) *got
451 = (const ElfW(Addr) *) D_PTR (map, l_info[DT_PLTGOT]);
452 const ElfW(Word) local_gotno
453 = ((const ElfW(Word))
454 map->l_info[DT_MIPS (LOCAL_GOTNO)]->d_un.d_val);
455
456 ElfW(Addr) reloc_value = got[symidx + local_gotno - gotsym];
457 __builtin_memcpy (reloc_addr, &reloc_value, sizeof (reloc_value));
458 }
459 }
460 break;
461 #endif
462 case R_MIPS_NONE: /* Alright, Wilbur. */
463 break;
464 #if _MIPS_SIM == _ABI64
465 case R_MIPS_64:
466 /* For full compliance with the ELF64 ABI, one must precede the
467 _REL32/_64 pair of relocations with a _64 relocation, such
468 that the in-place addend is read as a 64-bit value. IRIX
469 didn't pick up on this requirement, so we treat the
470 _REL32/_64 relocation as a 64-bit relocation even if it's by
471 itself. For ABI compliance, we ignore such _64 dummy
472 relocations. For RELA, this may be simply removed, since
473 it's totally unnecessary. */
474 if (ELFW(R_SYM) (r_info) == 0)
475 break;
476 /* Fall through. */
477 #endif
478 default:
479 _dl_reloc_bad_type (map, r_type, 0);
480 break;
481 }
482 }
483
484 /* Perform the relocation specified by RELOC and SYM (which is fully resolved).
485 MAP is the object containing the reloc. */
486
487 auto inline void
488 __attribute__ ((always_inline))
489 elf_machine_rel (struct link_map *map, const ElfW(Rel) *reloc,
490 const ElfW(Sym) *sym, const struct r_found_version *version,
491 void *const reloc_addr)
492 {
493 elf_machine_reloc (map, reloc->r_info, sym, version, reloc_addr, 0, 1);
494 }
495
496 auto inline void
497 __attribute__((always_inline))
498 elf_machine_rel_relative (ElfW(Addr) l_addr, const ElfW(Rel) *reloc,
499 void *const reloc_addr)
500 {
501 /* XXX Nothing to do. There is no relative relocation, right? */
502 }
503
504 auto inline void
505 __attribute__((always_inline))
506 elf_machine_lazy_rel (struct link_map *map,
507 ElfW(Addr) l_addr, const ElfW(Rela) *reloc)
508 {
509 /* Do nothing. */
510 }
511
512 auto inline void
513 __attribute__ ((always_inline))
514 elf_machine_rela (struct link_map *map, const ElfW(Rela) *reloc,
515 const ElfW(Sym) *sym, const struct r_found_version *version,
516 void *const reloc_addr)
517 {
518 elf_machine_reloc (map, reloc->r_info, sym, version, reloc_addr,
519 reloc->r_addend, 0);
520 }
521
522 auto inline void
523 __attribute__((always_inline))
524 elf_machine_rela_relative (ElfW(Addr) l_addr, const ElfW(Rela) *reloc,
525 void *const reloc_addr)
526 {
527 }
528
529 #ifndef RTLD_BOOTSTRAP
530 /* Relocate GOT. */
531 auto inline void
532 __attribute__((always_inline))
533 elf_machine_got_rel (struct link_map *map, int lazy)
534 {
535 ElfW(Addr) *got;
536 ElfW(Sym) *sym;
537 const ElfW(Half) *vernum;
538 int i, n, symidx;
539
540 #define RESOLVE_GOTSYM(sym,vernum,sym_index) \
541 ({ \
542 const ElfW(Sym) *ref = sym; \
543 const struct r_found_version *version \
544 = vernum ? &map->l_versions[vernum[sym_index] & 0x7fff] : NULL; \
545 struct link_map *sym_map; \
546 sym_map = RESOLVE_MAP (&ref, version, R_MIPS_REL32); \
547 ref ? sym_map->l_addr + ref->st_value : 0; \
548 })
549
550 if (map->l_info[VERSYMIDX (DT_VERSYM)] != NULL)
551 vernum = (const void *) D_PTR (map, l_info[VERSYMIDX (DT_VERSYM)]);
552 else
553 vernum = NULL;
554
555 got = (ElfW(Addr) *) D_PTR (map, l_info[DT_PLTGOT]);
556
557 n = map->l_info[DT_MIPS (LOCAL_GOTNO)]->d_un.d_val;
558 /* The dynamic linker's local got entries have already been relocated. */
559 if (map != &GL(dl_rtld_map))
560 {
561 /* got[0] is reserved. got[1] is also reserved for the dynamic object
562 generated by gnu ld. Skip these reserved entries from relocation. */
563 i = (got[1] & ELF_MIPS_GNU_GOT1_MASK)? 2 : 1;
564
565 /* Add the run-time displacement to all local got entries if
566 needed. */
567 if (__builtin_expect (map->l_addr != 0, 0))
568 {
569 while (i < n)
570 got[i++] += map->l_addr;
571 }
572 }
573
574 /* Handle global got entries. */
575 got += n;
576 /* Keep track of the symbol index. */
577 symidx = map->l_info[DT_MIPS (GOTSYM)]->d_un.d_val;
578 sym = (ElfW(Sym) *) D_PTR (map, l_info[DT_SYMTAB]) + symidx;
579 i = (map->l_info[DT_MIPS (SYMTABNO)]->d_un.d_val
580 - map->l_info[DT_MIPS (GOTSYM)]->d_un.d_val);
581
582 /* This loop doesn't handle Quickstart. */
583 while (i--)
584 {
585 if (sym->st_shndx == SHN_UNDEF)
586 {
587 if (ELFW(ST_TYPE) (sym->st_info) == STT_FUNC
588 && sym->st_value && lazy)
589 *got = sym->st_value + map->l_addr;
590 else
591 *got = RESOLVE_GOTSYM (sym, vernum, symidx);
592 }
593 else if (sym->st_shndx == SHN_COMMON)
594 *got = RESOLVE_GOTSYM (sym, vernum, symidx);
595 else if (ELFW(ST_TYPE) (sym->st_info) == STT_FUNC
596 && *got != sym->st_value
597 && lazy)
598 *got += map->l_addr;
599 else if (ELFW(ST_TYPE) (sym->st_info) == STT_SECTION)
600 {
601 if (sym->st_other == 0)
602 *got += map->l_addr;
603 }
604 else
605 *got = RESOLVE_GOTSYM (sym, vernum, symidx);
606
607 ++got;
608 ++sym;
609 ++symidx;
610 }
611
612 #undef RESOLVE_GOTSYM
613 }
614 #endif
615
616 /* Set up the loaded object described by L so its stub function
617 will jump to the on-demand fixup code __dl_runtime_resolve. */
618
619 auto inline int
620 __attribute__((always_inline))
621 elf_machine_runtime_setup (struct link_map *l, int lazy, int profile)
622 {
623 # ifndef RTLD_BOOTSTRAP
624 ElfW(Addr) *got;
625 extern void _dl_runtime_resolve (ElfW(Word));
626 extern int _dl_mips_gnu_objects;
627
628 if (lazy)
629 {
630 /* The GOT entries for functions have not yet been filled in.
631 Their initial contents will arrange when called to put an
632 offset into the .dynsym section in t8, the return address
633 in t7 and then jump to _GLOBAL_OFFSET_TABLE[0]. */
634 got = (ElfW(Addr) *) D_PTR (l, l_info[DT_PLTGOT]);
635
636 /* This function will get called to fix up the GOT entry indicated by
637 the register t8, and then jump to the resolved address. */
638 got[0] = (ElfW(Addr)) &_dl_runtime_resolve;
639
640 /* Store l to _GLOBAL_OFFSET_TABLE[1] for gnu object. The MSB
641 of got[1] of a gnu object is set to identify gnu objects.
642 Where we can store l for non gnu objects? XXX */
643 if ((got[1] & ELF_MIPS_GNU_GOT1_MASK) != 0)
644 got[1] = ((ElfW(Addr)) l | ELF_MIPS_GNU_GOT1_MASK);
645 else
646 _dl_mips_gnu_objects = 0;
647 }
648
649 /* Relocate global offset table. */
650 elf_machine_got_rel (l, lazy);
651
652 # endif
653 return lazy;
654 }
655
656 #endif /* RESOLVE_MAP */