]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/sparc/dl-machine.h
1 /* Machine-dependent ELF dynamic relocation inline functions. SPARC version.
2 Copyright (C) 1996, 1997 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 Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 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 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If
17 not, write to the Free Software Foundation, Inc.,
18 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20 #define ELF_MACHINE_NAME "sparc"
27 /* Some SPARC opcodes we need to use for self-modifying code. */
28 #define OPCODE_NOP 0x01000000 /* nop */
29 #define OPCODE_CALL 0x40000000 /* call ?; add PC-rel word address */
30 #define OPCODE_SETHI_G1 0x03000000 /* sethi ?, %g1; add value>>10 */
31 #define OPCODE_JMP_G1 0x81c06000 /* jmp %g1+?; add lo 10 bits of value */
32 #define OPCODE_SAVE_SP64 0x9de3bfc0 /* save %sp, -64, %sp */
35 /* Return nonzero iff E_MACHINE is compatible with the running host. */
37 elf_machine_matches_host (Elf32_Half e_machine
)
39 return e_machine
== EM_SPARC
;
43 /* Return the link-time address of _DYNAMIC. Conveniently, this is the
44 first element of the GOT. This must be inlined in a function which
46 static inline Elf32_Addr
47 elf_machine_dynamic (void)
49 register Elf32_Addr
*got
asm ("%l7");
54 /* Return the run-time load address of the shared object. */
55 static inline Elf32_Addr
56 elf_machine_load_address (void)
61 "add %%fp,0x44,%%o2\n\t" /* o2 = point to argc */
62 "ld [%%o2 - 4],%%o0\n\t" /* o0 = load argc */
63 "sll %%o0, 2, %%o0\n\t" /* o0 = argc * sizeof (int) */
64 "add %%o2,%%o0,%%o2\n\t" /* o2 = skip over argv */
65 "add %%o2,4,%%o2\n\t" /* skip over null after argv */
67 /* Now %o2 is pointing to env, skip over that as well. */
74 /* Note that above, we want to advance the NULL after envp so
77 /* Now, search for the AT_BASE property. */
83 "cmp %%o0,7\n\t" /* AT_BASE = 7 */
88 /* At this point %0 has the load address for the interpreter */
97 /* Perform the relocation specified by RELOC and SYM (which is fully resolved).
98 MAP is the object containing the reloc. */
101 elf_machine_rela (struct link_map
*map
, const Elf32_Rela
*reloc
,
102 const Elf32_Sym
*sym
, const struct r_found_version
*version
)
104 Elf32_Addr
*const reloc_addr
= (void *) (map
->l_addr
+ reloc
->r_offset
);
107 if (ELF32_R_TYPE (reloc
->r_info
) == R_SPARC_RELATIVE
)
109 #ifndef RTLD_BOOTSTRAP
110 if (map
!= &_dl_rtld_map
) /* Already done in rtld itself. */
112 *reloc_addr
+= map
->l_addr
+ reloc
->r_addend
;
117 if (sym
->st_shndx
!= SHN_UNDEF
&&
118 ELF32_ST_BIND (sym
->st_info
) == STB_LOCAL
)
122 value
= RESOLVE (&sym
, version
, ELF32_R_TYPE (reloc
->r_info
));
124 value
+= sym
->st_value
;
126 value
+= reloc
->r_addend
; /* Assume copy relocs have zero addend. */
128 switch (ELF32_R_TYPE (reloc
->r_info
))
131 memcpy (reloc_addr
, (void *) value
, sym
->st_size
);
133 case R_SPARC_GLOB_DAT
:
137 case R_SPARC_JMP_SLOT
:
138 reloc_addr
[1] = OPCODE_SETHI_G1
| (value
>> 10);
139 reloc_addr
[2] = OPCODE_JMP_G1
| (value
& 0x3ff);
142 *(char *) reloc_addr
= value
;
145 *(short *) reloc_addr
= value
;
148 *(char *) reloc_addr
= (value
- (Elf32_Addr
) reloc_addr
);
151 *(short *) reloc_addr
= (value
- (Elf32_Addr
) reloc_addr
);
154 *reloc_addr
= (value
- (Elf32_Addr
) reloc_addr
);
157 *reloc_addr
= (*reloc_addr
& ~0x3ff) | (value
& 0x3ff);
159 case R_SPARC_WDISP30
:
160 *reloc_addr
= ((*reloc_addr
& 0xc0000000)
161 | ((value
- (unsigned int) reloc_addr
) >> 2));
164 *reloc_addr
= (*reloc_addr
& 0xffc00000) | (value
>> 10);
166 case R_SPARC_NONE
: /* Alright, Wilbur. */
169 assert (! "unexpected dynamic reloc type");
176 elf_machine_lazy_rel (struct link_map
*map
, const Elf32_Rela
*reloc
)
178 switch (ELF32_R_TYPE (reloc
->r_info
))
182 case R_SPARC_JMP_SLOT
:
185 assert (! "unexpected PLT reloc type");
192 /* Nonzero iff TYPE should not be allowed to resolve to one of
193 the main executable's symbols, as for a COPY reloc. */
194 #define elf_machine_lookup_noexec_p(type) ((type) == R_SPARC_COPY)
196 /* Nonzero iff TYPE describes relocation of a PLT entry, so
197 PLT entries should not be allowed to define the value. */
198 #define elf_machine_lookup_noplt_p(type) ((type) == R_SPARC_JMP_SLOT)
200 /* A reloc type used for ld.so cmdline arg lookups to reject PLT entries. */
201 #define ELF_MACHINE_RELOC_NOPLT R_SPARC_JMP_SLOT
203 /* The SPARC never uses Elf32_Rel relocations. */
204 #define ELF_MACHINE_NO_REL 1
207 /* Set up the loaded object described by L so its unrelocated PLT
208 entries will jump to the on-demand fixup code in dl-runtime.c. */
211 elf_machine_runtime_setup (struct link_map
*l
, int lazy
)
214 extern void _dl_runtime_resolve (Elf32_Word
);
216 if (l
->l_info
[DT_JMPREL
] && lazy
)
218 /* The entries for functions in the PLT have not yet been filled in.
219 Their initial contents will arrange when called to set the high 22
220 bits of %g1 with an offset into the .rela.plt section and jump to
221 the beginning of the PLT. */
222 plt
= (Elf32_Addr
*) (l
->l_addr
+ l
->l_info
[DT_PLTGOT
]->d_un
.d_ptr
);
224 /* The beginning of the PLT does:
227 pltpc: call _dl_runtime_resolve
231 This saves the register window containing the arguments, and the
232 PC value (pltpc) implicitly saved in %o7 by the call points near the
233 location where we store the link_map pointer for this object. */
235 plt
[0] = OPCODE_SAVE_SP64
; /* save %sp, -64, %sp */
236 /* Construct PC-relative word address. */
237 plt
[1] = OPCODE_CALL
| (((Elf32_Addr
) &_dl_runtime_resolve
-
238 (Elf32_Addr
) &plt
[1]) >> 2);
239 plt
[2] = OPCODE_NOP
; /* Fill call delay slot. */
240 plt
[3] = (Elf32_Addr
*) l
;
243 /* This code is used in dl-runtime.c to call the `fixup' function
244 and then redirect to the address it returns. */
245 #define ELF_MACHINE_RUNTIME_TRAMPOLINE asm ("\
246 # Trampoline for _dl_runtime_resolver
247 .globl _dl_runtime_resolve
248 .type _dl_runtime_resolve, @function
252 # Pass two args to fixup: the PLT address computed from the PC saved
253 # in the PLT's call insn, and the reloc offset passed in %g1.
254 #ld [%o7 + 8], %o1 | Second arg, loaded from PLTPC[2].
256 #shrl %g1, 22, %o0 | First arg, set in delay slot of call.
257 # Jump to the real function.
259 # In the delay slot of that jump, restore the register window
260 # saved by the first insn of the PLT.
262 .size _dl_runtime_resolve, . - _dl_runtime_resolve
264 /* The PLT uses Elf32_Rela relocs. */
265 #define elf_machine_relplt elf_machine_rela
269 /* Mask identifying addresses reserved for the user program,
270 where the dynamic linker should not map anything. */
271 #define ELF_MACHINE_USER_ADDRESS_MASK ???
273 /* Initial entry point code for the dynamic linker.
274 The C function `_dl_start' is the real entry point;
275 its return value is the user program's entry point. */
277 #define RTLD_START __asm__ ( \
280 .type _start,@function\n\
282 /* Pass pointer to argument block to _dl_start. */\n\
293 sethi %hi(_GLOBAL_OFFSET_TABLE_-(2b-.)),%l2\n\
294 sethi %hi(_dl_default_scope),%l3\n\
295 or %l2,%lo(_GLOBAL_OFFSET_TABLE_-(2b-.)),%l2\n\
296 or %l3,%lo(_dl_default_scope),%l3\n\
298 # %l1 has the GOT. %l3 has _dl_default_scope offset\n\
299 # Now, load _dl_default_scope [2]\n\
302 # %l4 has _dl_default_scope [2]\n\
303 # call _dl_init_next until it returns 0, pass _dl_default_scope [2]\n\
305 call _dl_init_next\n\
314 # Clear the _dl_starting_up variable and pass _dl_fini in %g1 as per ELF ABI.\n\
315 sethi %hi(_dl_starting_up),%l4\n\
316 sethi %hi(_dl_fini),%l3\n\
317 or %l4,%lo(_dl_starting_up),%l4\n\
318 or %l3,%lo(_dl_fini),%l3\n\
319 # clear _dl_starting_up\n\
322 # load out fini function for atexit in %g1\n\
324 # jump to the user program entry point.\n\