1 /* Machine-dependent ELF dynamic relocation inline functions. SPARC version.
2 Copyright (C) 1996 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 0x04000000 /* 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
)
49 /* Return the link-time address of _DYNAMIC. Conveniently, this is the
50 first element of the GOT. This must be inlined in a function which
52 static inline Elf32_Addr
53 elf_machine_dynamic (void)
55 register Elf32_Addr
*got
asm ("%l7");
60 /* Return the run-time load address of the shared object. */
61 static inline Elf32_Addr
62 elf_machine_load_address (void)
69 /* The `subl' insn above will contain an R_68K_RELATIVE relocation
70 entry intended to insert the run-time address of the label `here'.
71 This will be the first relocation in the text of the dynamic
72 linker; we skip it to avoid trying to modify read-only text in this
74 #define ELF_MACHINE_BEFORE_RTLD_RELOC(dynamic_info) \
75 ((dynamic_info)[DT_RELA]->d_un.d_ptr += sizeof (Elf32_Rela), \
76 (dynamic_info)[DT_RELASZ]->d_un.d_val -= sizeof (Elf32_Rela))
78 /* Perform the relocation specified by RELOC and SYM (which is fully resolved).
79 MAP is the object containing the reloc. */
82 elf_machine_rela (struct link_map
*map
,
83 const Elf32_Rela
*reloc
, const Elf32_Sym
*sym
,
84 Elf32_Addr (*resolve
) (const Elf32_Sym
**ref
,
85 Elf32_Addr reloc_addr
,
88 Elf32_Addr
*const reloc_addr
= (void *) (map
->l_addr
+ reloc
->r_offset
);
91 switch (ELF32_R_TYPE (reloc
->r_info
))
94 loadbase
= (*resolve
) (&sym
, (Elf32_Addr
) reloc_addr
, 0);
95 memcpy (reloc_addr
, (void *) (loadbase
+ sym
->st_value
), sym
->st_size
);
97 case R_SPARC_GLOB_DAT
:
99 loadbase
= (resolve
? (*resolve
) (&sym
, (Elf32_Addr
) reloc_addr
, 0) :
100 /* RESOLVE is null during bootstrap relocation. */
102 *reloc_addr
= ((sym
? (loadbase
+ sym
->st_value
) : 0)
105 case R_SPARC_JMP_SLOT
:
106 loadbase
= (resolve
? (*resolve
) (&sym
, (Elf32_Addr
) reloc_addr
, 1) :
107 /* RESOLVE is null during bootstrap relocation. */
110 Elf32_Addr value
= ((sym
? (loadbase
+ sym
->st_value
) : 0)
112 reloc_addr
[1] = OPCODE_SETHI
| (value
>> 10);
113 reloc_addr
[2] = OPCODE_JMP_G1
| (value
& 0x3ff);
117 loadbase
= (*resolve
) (&sym
, (Elf32_Addr
) reloc_addr
, 0);
118 *(char *) reloc_addr
= ((sym
? (loadbase
+ sym
->st_value
) : 0)
122 loadbase
= (*resolve
) (&sym
, (Elf32_Addr
) reloc_addr
, 0);
123 *(short *) reloc_addr
= ((sym
? (loadbase
+ sym
->st_value
) : 0)
127 loadbase
= (resolve
? (*resolve
) (&sym
, (Elf32_Addr
) reloc_addr
, 0) :
128 /* RESOLVE is null during bootstrap relocation. */
131 case R_SPARC_RELATIVE
:
132 *reloc_addr
= map
->l_addr
+ reloc
->r_addend
;
135 loadbase
= (*resolve
) (&sym
, (Elf32_Addr
) reloc_addr
, 0);
136 *(char *) reloc_addr
= ((sym
? (loadbase
+ sym
->st_value
) : 0)
138 - (Elf32_Addr
) reloc_addr
);
141 loadbase
= (*resolve
) (&sym
, (Elf32_Addr
) reloc_addr
, 0);
142 *(short *) reloc_addr
= ((sym
? (loadbase
+ sym
->st_value
) : 0)
144 - (Elf32_Addr
) reloc_addr
);
147 loadbase
= (*resolve
) (&sym
, (Elf32_Addr
) reloc_addr
, 0);
148 *reloc_addr
= ((sym
? (loadbase
+ sym
->st_value
) : 0)
150 - (Elf32_Addr
) reloc_addr
);
152 case R_SPARC_NONE
: /* Alright, Wilbur. */
155 assert (! "unexpected dynamic reloc type");
161 elf_machine_lazy_rel (struct link_map
*map
, const Elf32_Rela
*reloc
)
163 switch (ELF32_R_TYPE (reloc
->r_info
))
167 case R_SPARC_JMP_SLOT
:
170 assert (! "unexpected PLT reloc type");
175 /* Nonzero iff TYPE describes relocation of a PLT entry, so
176 PLT entries should not be allowed to define the value. */
177 #define elf_machine_pltrel_p(type) ((type) == R_SPARC_JMP_SLOT)
179 /* The SPARC never uses Elf32_Rel relocations. */
180 #define ELF_MACHINE_NO_REL 1
183 /* Set up the loaded object described by L so its unrelocated PLT
184 entries will jump to the on-demand fixup code in dl-runtime.c. */
187 elf_machine_runtime_setup (struct link_map
*l
, int lazy
)
190 extern void _dl_runtime_resolve (Elf32_Word
);
192 if (l
->l_info
[DT_JMPREL
] && lazy
)
194 /* The entries for functions in the PLT have not yet been filled in.
195 Their initial contents will arrange when called to set the high 22
196 bits of %g1 with an offset into the .rela.plt section and jump to
197 the beginning of the PLT. */
198 plt
= (Elf32_Addr
*) (l
->l_addr
+ l
->l_info
[DT_PLTGOT
]->d_un
.d_ptr
);
200 /* The beginning of the PLT does:
203 pltpc: call _dl_runtime_resolve
207 This saves the register window containing the arguments, and the
208 PC value (pltpc) implicitly saved in %o7 by the call points near the
209 location where we store the link_map pointer for this object. */
211 plt
[0] = OPCODE_SAVE_SP64
; /* save %sp, -64, %sp */
212 /* Construct PC-relative word address. */
213 plt
[1] = OPCODE_CALL
| (((Elf32_Addr
) &_dl_runtime_resolve
-
214 (Elf32_Addr
) &plt
[1]) >> 2);
215 plt
[2] = OPCODE_NOP
; /* Fill call delay slot. */
219 /* This code is used in dl-runtime.c to call the `fixup' function
220 and then redirect to the address it returns. */
221 #define ELF_MACHINE_RUNTIME_TRAMPOLINE asm ("\
222 | Trampoline for _dl_runtime_resolver
223 .globl _dl_runtime_resolve
224 .type _dl_runtime_resolve, @function
226 | Pass two args to fixup: the PLT address computed from the PC saved
227 | in the PLT's call insn, and the reloc offset passed in %g1.
228 ld [%o7 + 8], %o1 | Second arg, loaded from PLTPC[2].
230 shrl %g1, 22, %o0 | First arg, set in delay slot of call.
231 | Jump to the real function.
233 | In the delay slot of that jump, restore the register window
234 | saved by the first insn of the PLT.
236 .size _dl_runtime_resolve, . - _dl_runtime_resolve
238 /* The PLT uses Elf32_Rela relocs. */
239 #define elf_machine_relplt elf_machine_rela
243 /* Mask identifying addresses reserved for the user program,
244 where the dynamic linker should not map anything. */
245 #define ELF_MACHINE_USER_ADDRESS_MASK ???
247 /* Initial entry point code for the dynamic linker.
248 The C function `_dl_start' is the real entry point;
249 its return value is the user program's entry point. */
251 #define RTLD_START asm (???)