1 /* Machine-dependent ELF dynamic relocation inline functions. Sparc64 version.
2 Copyright (C) 1997,1998,1999,2000,2001,2002 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 #define ELF_MACHINE_NAME "sparc64"
23 #include <sys/param.h>
28 # define VALIDX(tag) (DT_NUM + DT_THISPROCNUM + DT_VERSIONTAGNUM \
29 + DT_EXTRANUM + DT_VALTAGIDX (tag))
32 #define ELF64_R_TYPE_ID(info) ((info) & 0xff)
33 #define ELF64_R_TYPE_DATA(info) ((info) >> 8)
35 /* Return nonzero iff ELF header is compatible with the running host. */
37 elf_machine_matches_host (const Elf64_Ehdr
*ehdr
)
39 return ehdr
->e_machine
== EM_SPARCV9
;
42 /* We have to do this because elf_machine_{dynamic,load_address} can be
43 invoked from functions that have no GOT references, and thus the compiler
44 has no obligation to load the PIC register. */
45 #define LOAD_PIC_REG(PIC_REG) \
46 do { Elf64_Addr tmp; \
47 __asm("sethi %%hi(_GLOBAL_OFFSET_TABLE_-4), %1\n\t" \
49 "add %1, %%lo(_GLOBAL_OFFSET_TABLE_+4), %1\n\t" \
51 : "=r" (PIC_REG), "=r" (tmp)); \
54 /* Return the link-time address of _DYNAMIC. Conveniently, this is the
55 first element of the GOT. This must be inlined in a function which
57 static inline Elf64_Addr
58 elf_machine_dynamic (void)
60 register Elf64_Addr
*elf_pic_register
__asm__("%l7");
62 LOAD_PIC_REG (elf_pic_register
);
64 return *elf_pic_register
;
67 /* Return the run-time load address of the shared object. */
68 static inline Elf64_Addr
69 elf_machine_load_address (void)
71 register Elf32_Addr
*pc
__asm ("%o7");
72 register Elf64_Addr
*got
__asm ("%l7");
74 __asm ("sethi %%hi(_GLOBAL_OFFSET_TABLE_-4), %1\n\t"
76 " add %1, %%lo(_GLOBAL_OFFSET_TABLE_+4), %1\n\t"
78 "call _GLOBAL_OFFSET_TABLE_\n"
79 "1:\tadd %1, %0, %1\n\t" : "=r" (pc
), "=r" (got
));
81 /* got is now l_addr + _GLOBAL_OFFSET_TABLE_
83 pc[2]*4 is l_addr + _DYNAMIC - (long)pc - 8
84 pc[3]*4 is l_addr + _GLOBAL_OFFSET_TABLE_ - (long)pc - 12 */
85 return (Elf64_Addr
) got
- *got
+ (Elf32_Sword
) ((pc
[2] - pc
[3]) * 4) - 4;
88 /* We have 4 cases to handle. And we code different code sequences
89 for each one. I love V9 code models... */
91 sparc64_fixup_plt (struct link_map
*map
, const Elf64_Rela
*reloc
,
92 Elf64_Addr
*reloc_addr
, Elf64_Addr value
,
93 Elf64_Addr high
, int t
)
95 unsigned int *insns
= (unsigned int *) reloc_addr
;
96 Elf64_Addr plt_vaddr
= (Elf64_Addr
) reloc_addr
;
97 Elf64_Sxword disp
= value
- plt_vaddr
;
99 /* Now move plt_vaddr up to the call instruction. */
100 plt_vaddr
+= ((t
+ 1) * 4);
102 /* PLT entries .PLT32768 and above look always the same. */
103 if (__builtin_expect (high
, 0) != 0)
105 *reloc_addr
= value
- map
->l_addr
;
107 /* Near destination. */
108 else if (disp
>= -0x800000 && disp
< 0x800000)
110 /* As this is just one instruction, it is thread safe and so
111 we can avoid the unnecessary sethi FOO, %g1.
113 insns
[0] = 0x30800000 | ((disp
>> 2) & 0x3fffff);
114 __asm
__volatile ("flush %0" : : "r" (insns
));
116 /* 32-bit Sparc style, the target is in the lower 32-bits of
118 else if (insns
+= t
, (value
>> 32) == 0)
120 /* sethi %hi(target), %g1
121 jmpl %g1 + %lo(target), %g0 */
123 insns
[1] = 0x81c06000 | (value
& 0x3ff);
124 __asm
__volatile ("flush %0 + 4" : : "r" (insns
));
126 insns
[0] = 0x03000000 | ((unsigned int)(value
>> 10));
127 __asm
__volatile ("flush %0" : : "r" (insns
));
129 /* We can also get somewhat simple sequences if the distance between
130 the target and the PLT entry is within +/- 2GB. */
131 else if ((plt_vaddr
> value
132 && ((plt_vaddr
- value
) >> 31) == 0)
133 || (value
> plt_vaddr
134 && ((value
- plt_vaddr
) >> 31) == 0))
136 unsigned int displacement
;
138 if (plt_vaddr
> value
)
139 displacement
= (0 - (plt_vaddr
- value
));
141 displacement
= value
- plt_vaddr
;
147 insns
[2] = 0x9e100001;
148 __asm
__volatile ("flush %0 + 8" : : "r" (insns
));
150 insns
[1] = 0x40000000 | (displacement
>> 2);
151 __asm
__volatile ("flush %0 + 4" : : "r" (insns
));
153 insns
[0] = 0x8210000f;
154 __asm
__volatile ("flush %0" : : "r" (insns
));
156 /* Worst case, ho hum... */
159 unsigned int high32
= (value
>> 32);
160 unsigned int low32
= (unsigned int) value
;
162 /* ??? Some tricks can be stolen from the sparc64 egcs backend
163 constant formation code I wrote. -DaveM */
165 if (__builtin_expect (high32
& 0x3ff, 0))
167 /* sethi %hh(value), %g1
168 sethi %lm(value), %g5
169 or %g1, %hm(value), %g1
170 or %g5, %lo(value), %g5
175 insns
[5] = 0x81c04005;
176 __asm
__volatile ("flush %0 + 20" : : "r" (insns
));
178 insns
[4] = 0x83287020;
179 __asm
__volatile ("flush %0 + 16" : : "r" (insns
));
181 insns
[3] = 0x8a116000 | (low32
& 0x3ff);
182 __asm
__volatile ("flush %0 + 12" : : "r" (insns
));
184 insns
[2] = 0x82106000 | (high32
& 0x3ff);
188 /* sethi %hh(value), %g1
189 sethi %lm(value), %g5
191 or %g5, %lo(value), %g5
195 insns
[4] = 0x81c04005;
196 __asm
__volatile ("flush %0 + 16" : : "r" (insns
));
198 insns
[3] = 0x8a116000 | (low32
& 0x3ff);
199 __asm
__volatile ("flush %0 + 12" : : "r" (insns
));
201 insns
[2] = 0x83287020;
204 __asm
__volatile ("flush %0 + 8" : : "r" (insns
));
206 insns
[1] = 0x0b000000 | (low32
>> 10);
207 __asm
__volatile ("flush %0 + 4" : : "r" (insns
));
209 insns
[0] = 0x03000000 | (high32
>> 10);
210 __asm
__volatile ("flush %0" : : "r" (insns
));
214 static inline Elf64_Addr
215 elf_machine_fixup_plt (struct link_map
*map
, lookup_t t
,
216 const Elf64_Rela
*reloc
,
217 Elf64_Addr
*reloc_addr
, Elf64_Addr value
)
219 sparc64_fixup_plt (map
, reloc
, reloc_addr
, value
+ reloc
->r_addend
,
224 /* Return the final value of a plt relocation. */
225 static inline Elf64_Addr
226 elf_machine_plt_value (struct link_map
*map
, const Elf64_Rela
*reloc
,
229 /* Don't add addend here, but in elf_machine_fixup_plt instead.
230 value + reloc->r_addend is the value which should actually be
231 stored into .plt data slot. */
237 /* Perform the relocation specified by RELOC and SYM (which is fully resolved).
238 MAP is the object containing the reloc. */
241 elf_machine_rela (struct link_map
*map
, const Elf64_Rela
*reloc
,
242 const Elf64_Sym
*sym
, const struct r_found_version
*version
,
243 Elf64_Addr
*const reloc_addr
)
245 const unsigned long int r_type
= ELF64_R_TYPE_ID (reloc
->r_info
);
247 #if !defined RTLD_BOOTSTRAP || !defined HAVE_Z_COMBRELOC
248 if (__builtin_expect (r_type
== R_SPARC_RELATIVE
, 0))
249 *reloc_addr
= map
->l_addr
+ reloc
->r_addend
;
250 # ifndef RTLD_BOOTSTRAP
251 else if (r_type
== R_SPARC_NONE
) /* Who is Wilbur? */
257 #if !defined RTLD_BOOTSTRAP && !defined RESOLVE_CONFLICT_FIND_MAP
258 const Elf64_Sym
*const refsym
= sym
;
261 #ifndef RESOLVE_CONFLICT_FIND_MAP
262 if (sym
->st_shndx
!= SHN_UNDEF
&&
263 ELF64_ST_BIND (sym
->st_info
) == STB_LOCAL
)
267 value
= RESOLVE (&sym
, version
, r_type
);
269 value
+= sym
->st_value
;
274 value
+= reloc
->r_addend
; /* Assume copy relocs have zero addend. */
278 #if !defined RTLD_BOOTSTRAP && !defined RESOLVE_CONFLICT_FIND_MAP
281 /* This can happen in trace mode if an object could not be
284 if (sym
->st_size
> refsym
->st_size
285 || (GL(dl_verbose
) && sym
->st_size
< refsym
->st_size
))
289 strtab
= (const void *) D_PTR (map
, l_info
[DT_STRTAB
]);
291 %s: Symbol `%s' has different size in shared object, consider re-linking\n",
292 rtld_progname
?: "<program name unknown>",
293 strtab
+ refsym
->st_name
);
295 memcpy (reloc_addr
, (void *) value
, MIN (sym
->st_size
,
300 case R_SPARC_GLOB_DAT
:
303 #ifndef RTLD_BOOTSTRAP
305 *(char *) reloc_addr
= value
;
308 *(short *) reloc_addr
= value
;
311 *(unsigned int *) reloc_addr
= value
;
314 *(char *) reloc_addr
= (value
- (Elf64_Addr
) reloc_addr
);
317 *(short *) reloc_addr
= (value
- (Elf64_Addr
) reloc_addr
);
320 *(unsigned int *) reloc_addr
= (value
- (Elf64_Addr
) reloc_addr
);
322 case R_SPARC_WDISP30
:
323 *(unsigned int *) reloc_addr
=
324 ((*(unsigned int *)reloc_addr
& 0xc0000000) |
325 ((value
- (Elf64_Addr
) reloc_addr
) >> 2));
328 /* MEDLOW code model relocs */
330 *(unsigned int *) reloc_addr
=
331 ((*(unsigned int *)reloc_addr
& ~0x3ff) |
335 *(unsigned int *) reloc_addr
=
336 ((*(unsigned int *)reloc_addr
& 0xffc00000) |
340 *(unsigned int *) reloc_addr
=
341 ((*(unsigned int *)reloc_addr
& ~0x1fff) |
342 (((value
& 0x3ff) + ELF64_R_TYPE_DATA (reloc
->r_info
)) & 0x1fff));
345 /* MEDMID code model relocs */
347 *(unsigned int *) reloc_addr
=
348 ((*(unsigned int *)reloc_addr
& 0xffc00000) |
352 *(unsigned int *) reloc_addr
=
353 ((*(unsigned int *)reloc_addr
& ~0x3ff) |
354 ((value
>> 12) & 0x3ff));
357 *(unsigned int *) reloc_addr
=
358 ((*(unsigned int *)reloc_addr
& ~0xfff) |
362 /* MEDANY code model relocs */
364 *(unsigned int *) reloc_addr
=
365 ((*(unsigned int *)reloc_addr
& 0xffc00000) |
369 *(unsigned int *) reloc_addr
=
370 ((*(unsigned int *)reloc_addr
& ~0x3ff) |
371 ((value
>> 32) & 0x3ff));
374 *(unsigned int *) reloc_addr
=
375 ((*(unsigned int *)reloc_addr
& 0xffc00000) |
376 ((value
>> 10) & 0x003fffff));
379 case R_SPARC_JMP_SLOT
:
380 #ifdef RESOLVE_CONFLICT_FIND_MAP
381 /* R_SPARC_JMP_SLOT conflicts against .plt[32768+]
382 relocs should be turned into R_SPARC_64 relocs
383 in .gnu.conflict section.
384 r_addend non-zero does not mean it is a .plt[32768+]
385 reloc, instead it is the actual address of the function
387 sparc64_fixup_plt (NULL
, reloc
, reloc_addr
, value
, 0, 0);
389 sparc64_fixup_plt (map
, reloc
, reloc_addr
, value
,
393 #ifndef RTLD_BOOTSTRAP
395 ((unsigned char *) reloc_addr
) [0] = value
>> 8;
396 ((unsigned char *) reloc_addr
) [1] = value
;
399 ((unsigned char *) reloc_addr
) [0] = value
>> 24;
400 ((unsigned char *) reloc_addr
) [1] = value
>> 16;
401 ((unsigned char *) reloc_addr
) [2] = value
>> 8;
402 ((unsigned char *) reloc_addr
) [3] = value
;
405 if (! ((long) reloc_addr
& 3))
407 /* Common in .eh_frame */
408 ((unsigned int *) reloc_addr
) [0] = value
>> 32;
409 ((unsigned int *) reloc_addr
) [1] = value
;
412 ((unsigned char *) reloc_addr
) [0] = value
>> 56;
413 ((unsigned char *) reloc_addr
) [1] = value
>> 48;
414 ((unsigned char *) reloc_addr
) [2] = value
>> 40;
415 ((unsigned char *) reloc_addr
) [3] = value
>> 32;
416 ((unsigned char *) reloc_addr
) [4] = value
>> 24;
417 ((unsigned char *) reloc_addr
) [5] = value
>> 16;
418 ((unsigned char *) reloc_addr
) [6] = value
>> 8;
419 ((unsigned char *) reloc_addr
) [7] = value
;
422 #if !defined RTLD_BOOTSTRAP || defined _NDEBUG
424 _dl_reloc_bad_type (map
, r_type
, 0);
432 elf_machine_rela_relative (Elf64_Addr l_addr
, const Elf64_Rela
*reloc
,
433 Elf64_Addr
*const reloc_addr
)
435 *reloc_addr
= l_addr
+ reloc
->r_addend
;
439 elf_machine_lazy_rel (struct link_map
*map
,
440 Elf64_Addr l_addr
, const Elf64_Rela
*reloc
)
442 switch (ELF64_R_TYPE (reloc
->r_info
))
446 case R_SPARC_JMP_SLOT
:
449 _dl_reloc_bad_type (map
, ELFW(R_TYPE
) (reloc
->r_info
), 1);
456 /* ELF_RTYPE_CLASS_PLT iff TYPE describes relocation of a PLT entry, so
457 PLT entries should not be allowed to define the value.
458 ELF_RTYPE_CLASS_NOCOPY iff TYPE should not be allowed to resolve to one
459 of the main executable's symbols, as for a COPY reloc. */
460 #define elf_machine_type_class(type) \
461 ((((type) == R_SPARC_JMP_SLOT) * ELF_RTYPE_CLASS_PLT) \
462 | (((type) == R_SPARC_COPY) * ELF_RTYPE_CLASS_COPY))
464 /* A reloc type used for ld.so cmdline arg lookups to reject PLT entries. */
465 #define ELF_MACHINE_JMP_SLOT R_SPARC_JMP_SLOT
467 /* The SPARC never uses Elf64_Rel relocations. */
468 #define ELF_MACHINE_NO_REL 1
470 /* The SPARC overlaps DT_RELA and DT_PLTREL. */
471 #define ELF_MACHINE_PLTREL_OVERLAP 1
473 /* Set up the loaded object described by L so its unrelocated PLT
474 entries will jump to the on-demand fixup code in dl-runtime.c. */
477 elf_machine_runtime_setup (struct link_map
*l
, int lazy
, int profile
)
479 if (l
->l_info
[DT_JMPREL
] && lazy
)
481 extern void _dl_runtime_resolve_0 (void);
482 extern void _dl_runtime_resolve_1 (void);
483 extern void _dl_runtime_profile_0 (void);
484 extern void _dl_runtime_profile_1 (void);
485 Elf64_Addr res0_addr
, res1_addr
;
486 unsigned int *plt
= (void *) D_PTR (l
, l_info
[DT_PLTGOT
]);
491 res0_addr
= (Elf64_Addr
) &_dl_runtime_resolve_0
;
492 res1_addr
= (Elf64_Addr
) &_dl_runtime_resolve_1
;
496 res0_addr
= (Elf64_Addr
) &_dl_runtime_profile_0
;
497 res1_addr
= (Elf64_Addr
) &_dl_runtime_profile_1
;
498 if (_dl_name_match_p (GL(dl_profile
), l
))
499 GL(dl_profile_map
) = l
;
505 sethi %hh(_dl_runtime_{resolve,profile}_0), %l0
506 sethi %lm(_dl_runtime_{resolve,profile}_0), %l1
507 or %l0, %hm(_dl_runtime_{resolve,profile}_0), %l0
508 or %l1, %lo(_dl_runtime_{resolve,profile}_0), %l1
511 sethi %hi(0xffc00), %l2
515 plt
[1] = 0x21000000 | (res0_addr
>> (64 - 22));
516 plt
[2] = 0x23000000 | ((res0_addr
>> 10) & 0x003fffff);
517 plt
[3] = 0xa0142000 | ((res0_addr
>> 32) & 0x3ff);
518 plt
[4] = 0xa2146000 | (res0_addr
& 0x3ff);
526 sethi %hh(_dl_runtime_{resolve,profile}_1), %l0
527 sethi %lm(_dl_runtime_{resolve,profile}_1), %l1
528 or %l0, %hm(_dl_runtime_{resolve,profile}_1), %l0
529 or %l1, %lo(_dl_runtime_{resolve,profile}_1), %l1
535 plt
[8 + 0] = 0x9de3bf40;
536 if (__builtin_expect (((res1_addr
+ 4) >> 32) & 0x3ff, 0))
540 plt
[8 + 1] = 0x21000000 | (res1_addr
>> (64 - 22));
541 plt
[8 + 2] = 0x23000000 | ((res1_addr
>> 10) & 0x003fffff);
542 if (__builtin_expect (i
, 0))
543 plt
[8 + 3] = 0xa0142000 | ((res1_addr
>> 32) & 0x3ff);
545 plt
[8 + 3] = 0xa12c3020;
546 plt
[8 + 4] = 0xa2146000 | (res1_addr
& 0x3ff);
547 if (__builtin_expect (i
, 0))
548 plt
[8 + 5] = 0xa12c3020;
549 plt
[8 + 5 + i
] = 0xadc40011;
550 plt
[8 + 6 + i
] = 0x9330700c;
552 /* Now put the magic cookie at the beginning of .PLT2
553 Entry .PLT3 is unused by this implementation. */
554 *((struct link_map
**)(&plt
[16 + 0])) = l
;
556 if (__builtin_expect (l
->l_info
[VALIDX(DT_GNU_PRELINKED
)] != NULL
, 0)
557 || __builtin_expect (l
->l_info
[VALIDX (DT_GNU_LIBLISTSZ
)] != NULL
, 0))
559 /* Need to reinitialize .plt to undo prelinking. */
560 Elf64_Rela
*rela
= (Elf64_Rela
*) D_PTR (l
, l_info
[DT_JMPREL
]);
562 = (Elf64_Rela
*) ((char *) rela
563 + l
->l_info
[DT_PLTRELSZ
]->d_un
.d_val
);
565 /* prelink must ensure there are no R_SPARC_NONE relocs left
567 while (rela
< relaend
)
569 if (__builtin_expect (rela
->r_addend
, 0) != 0)
571 Elf64_Addr slot
= ((rela
->r_offset
+ 0x400
574 + (Elf64_Addr
) plt
- 0x400;
575 /* ldx [%o7 + X], %g1 */
576 unsigned int first_ldx
= *(unsigned int *)(slot
+ 12);
577 Elf64_Addr ptr
= slot
+ (first_ldx
& 0xfff) + 4;
579 *(Elf64_Addr
*) rela
->r_offset
581 - (slot
+ ((rela
->r_offset
- ptr
) / 8) * 24 + 4);
586 *(unsigned int *) rela
->r_offset
587 = 0x03000000 | (rela
->r_offset
- (Elf64_Addr
) plt
);
588 *(unsigned int *) (rela
->r_offset
+ 4)
589 = 0x30680000 | ((((Elf64_Addr
) plt
+ 32
590 - rela
->r_offset
- 4) >> 2) & 0x7ffff);
591 __asm
__volatile ("flush %0" : : "r" (rela
->r_offset
));
592 __asm
__volatile ("flush %0+4" : : "r" (rela
->r_offset
));
601 /* This code is used in dl-runtime.c to call the `fixup' function
602 and then redirect to the address it returns. */
603 #define TRAMPOLINE_TEMPLATE(tramp_name, fixup_name) \
606 " .globl " #tramp_name "_0\n" \
607 " .type " #tramp_name "_0, @function\n" \
609 "\t" #tramp_name "_0:\n" \
610 " ! sethi %hi(1047552), %l2 - Done in .PLT0\n" \
611 " ldx [%l6 + 32 + 8], %o0\n" \
612 " sub %g1, %l6, %l0\n" \
613 " xor %l2, -1016, %l2\n" \
614 " sethi %hi(5120), %l3 ! 160 * 32\n" \
615 " add %l0, %l2, %l0\n" \
616 " sethi %hi(32768), %l4\n" \
617 " udivx %l0, %l3, %l3\n" \
618 " sllx %l3, 2, %l1\n" \
619 " add %l1, %l3, %l1\n" \
620 " sllx %l1, 10, %l2\n" \
621 " sub %l4, 4, %l4 ! No thanks to Sun for not obeying their own ABI\n" \
622 " sllx %l1, 5, %l1\n" \
623 " sub %l0, %l2, %l0\n" \
624 " udivx %l0, 24, %l0\n" \
625 " add %l0, %l4, %l0\n" \
626 " add %l1, %l0, %l1\n" \
627 " add %l1, %l1, %l0\n" \
628 " add %l0, %l1, %l0\n" \
630 " call " #fixup_name "\n" \
631 " sllx %l0, 3, %o1\n" \
634 " .size " #tramp_name "_0, . - " #tramp_name "_0\n" \
636 " .globl " #tramp_name "_1\n" \
637 " .type " #tramp_name "_1, @function\n" \
638 " ! tramp_name_1 + 4 needs to be .align 32\n" \
639 "\t" #tramp_name "_1:\n" \
640 " sub %l6, 4, %l6\n" \
641 " ! srlx %g1, 12, %o1 - Done in .PLT1\n" \
642 " ldx [%l6 + 12], %o0\n" \
643 " add %o1, %o1, %o3\n" \
644 " sub %o1, 96, %o1 ! No thanks to Sun for not obeying their own ABI\n" \
646 " call " #fixup_name "\n" \
647 " add %o1, %o3, %o1\n" \
650 " .size " #tramp_name "_1, . - " #tramp_name "_1\n" \
654 #define ELF_MACHINE_RUNTIME_TRAMPOLINE \
655 TRAMPOLINE_TEMPLATE (_dl_runtime_resolve, fixup); \
656 TRAMPOLINE_TEMPLATE (_dl_runtime_profile, profile_fixup);
658 #define ELF_MACHINE_RUNTIME_TRAMPOLINE \
659 TRAMPOLINE_TEMPLATE (_dl_runtime_resolve, fixup); \
660 TRAMPOLINE_TEMPLATE (_dl_runtime_profile, fixup);
663 /* The PLT uses Elf64_Rela relocs. */
664 #define elf_machine_relplt elf_machine_rela
666 /* Initial entry point code for the dynamic linker.
667 The C function `_dl_start' is the real entry point;
668 its return value is the user program's entry point. */
671 #define __S(x) __S1(x)
673 #define RTLD_START __asm__ ( "\n" \
675 " .global _start\n" \
676 " .type _start, @function\n" \
679 " /* Make room for functions to drop their arguments on the stack. */\n" \
680 " sub %sp, 6*8, %sp\n" \
681 " /* Pass pointer to argument block to _dl_start. */\n" \
682 " call _dl_start\n" \
683 " add %sp," __S(STACK_BIAS) "+22*8,%o0\n" \
684 " /* FALLTHRU */\n" \
685 " .size _start, .-_start\n" \
687 " .global _dl_start_user\n" \
688 " .type _dl_start_user, @function\n" \
689 "_dl_start_user:\n" \
690 " /* Load the GOT register. */\n" \
692 " sethi %hi(_GLOBAL_OFFSET_TABLE_-(1b-.)), %l7\n" \
693 "11: or %l7, %lo(_GLOBAL_OFFSET_TABLE_-(1b-.)), %l7\n" \
694 " /* Store the highest stack address. */\n" \
695 " sethi %hi(__libc_stack_end), %g5\n" \
696 " add %l7, %o7, %l7\n" \
697 " or %g5, %lo(__libc_stack_end), %g5\n" \
698 " /* Save the user entry point address in %l0. */\n" \
700 " ldx [%l7 + %g5], %l1\n" \
701 " sethi %hi(_dl_skip_args), %g5\n" \
702 " add %sp, 6*8, %l2\n" \
703 " /* See if we were run as a command with the executable file name as an\n" \
704 " extra leading argument. If so, we must shift things around since we\n" \
705 " must keep the stack doubleword aligned. */\n" \
706 " or %g5, %lo(_dl_skip_args), %g5\n" \
707 " stx %l2, [%l1]\n" \
708 " ldx [%l7 + %g5], %i0\n" \
710 " brz,pt %i0, 2f\n" \
711 " ldx [%sp + " __S(STACK_BIAS) " + 22*8], %i5\n" \
712 " /* Find out how far to shift. */\n" \
713 " sethi %hi(_dl_argv), %l4\n" \
714 " sub %i5, %i0, %i5\n" \
715 " or %l4, %lo(_dl_argv), %l4\n" \
716 " sllx %i0, 3, %l6\n" \
717 " ldx [%l7 + %l4], %l4\n" \
718 " stx %i5, [%sp + " __S(STACK_BIAS) " + 22*8]\n" \
719 " add %sp, " __S(STACK_BIAS) " + 23*8, %i1\n" \
720 " add %i1, %l6, %i2\n" \
721 " ldx [%l4], %l5\n" \
722 " /* Copy down argv. */\n" \
723 "12: ldx [%i2], %i3\n" \
724 " add %i2, 8, %i2\n" \
725 " stx %i3, [%i1]\n" \
726 " brnz,pt %i3, 12b\n" \
727 " add %i1, 8, %i1\n" \
728 " sub %l5, %l6, %l5\n" \
729 " /* Copy down envp. */\n" \
730 "13: ldx [%i2], %i3\n" \
731 " add %i2, 8, %i2\n" \
732 " stx %i3, [%i1]\n" \
733 " brnz,pt %i3, 13b\n" \
734 " add %i1, 8, %i1\n" \
735 " /* Copy down auxiliary table. */\n" \
736 "14: ldx [%i2], %i3\n" \
737 " ldx [%i2 + 8], %i4\n" \
738 " add %i2, 16, %i2\n" \
739 " stx %i3, [%i1]\n" \
740 " stx %i4, [%i1 + 8]\n" \
741 " brnz,pt %i3, 14b\n" \
742 " add %i1, 16, %i1\n" \
743 " stx %l5, [%l4]\n" \
744 " /* %o0 = _dl_loaded, %o1 = argc, %o2 = argv, %o3 = envp. */\n" \
745 "2: sethi %hi(_rtld_local), %o0\n" \
746 " add %sp, " __S(STACK_BIAS) " + 23*8, %o2\n" \
747 " orcc %o0, %lo(_rtld_local), %o0\n" \
748 " sllx %i5, 3, %o3\n" \
749 " ldx [%l7 + %o0], %o0\n" \
750 " add %o3, 8, %o3\n" \
752 " add %o2, %o3, %o3\n" \
753 " call _dl_init_internal\n" \
754 " ldx [%o0], %o0\n" \
755 " /* Pass our finalizer function to the user in %g1. */\n" \
756 " sethi %hi(_dl_fini), %g1\n" \
757 " or %g1, %lo(_dl_fini), %g1\n" \
758 " ldx [%l7 + %g1], %g1\n" \
759 " /* Jump to the user's entry point and deallocate the extra stack we got. */\n" \
761 " add %sp, 6*8, %sp\n" \
762 " .size _dl_start_user, . - _dl_start_user\n" \