]> sourceware.org Git - glibc.git/blob - sysdeps/m68k/dl-machine.h
Update.
[glibc.git] / sysdeps / m68k / dl-machine.h
1 /* Machine-dependent ELF dynamic relocation inline functions. m68k version.
2 Copyright (C) 1996, 1997 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
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.
9
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.
14
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. */
19
20 #ifndef dl_machine_h
21 #define dl_machine_h
22
23 #define ELF_MACHINE_NAME "m68k"
24
25 #include <sys/param.h>
26
27 #include <assert.h>
28
29 /* Return nonzero iff E_MACHINE is compatible with the running host. */
30 static inline int
31 elf_machine_matches_host (Elf32_Half e_machine)
32 {
33 switch (e_machine)
34 {
35 case EM_68K:
36 return 1;
37 default:
38 return 0;
39 }
40 }
41
42
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
45 uses global data. */
46 static inline Elf32_Addr
47 elf_machine_dynamic (void)
48 {
49 register Elf32_Addr *got asm ("%a5");
50 return *got;
51 }
52
53
54 /* Return the run-time load address of the shared object. */
55 static inline Elf32_Addr
56 elf_machine_load_address (void)
57 {
58 Elf32_Addr addr;
59 asm ("1: lea 1b(%%pc), %0\n"
60 " sub.l 1b@GOTPC(%%pc), %0"
61 : "=a" (addr));
62 return addr;
63 }
64
65
66 /* Set up the loaded object described by L so its unrelocated PLT
67 entries will jump to the on-demand fixup code in dl-runtime.c. */
68
69 static inline int
70 elf_machine_runtime_setup (struct link_map *l, int lazy, int profile)
71 {
72 Elf32_Addr *got;
73 extern void _dl_runtime_resolve (Elf32_Word);
74 extern void _dl_runtime_profile (Elf32_Word);
75
76 if (l->l_info[DT_JMPREL] && lazy)
77 {
78 /* The GOT entries for functions in the PLT have not yet been
79 filled in. Their initial contents will arrange when called
80 to push an offset into the .rela.plt section, push
81 _GLOBAL_OFFSET_TABLE_[1], and then jump to
82 _GLOBAL_OFFSET_TABLE_[2]. */
83 got = (Elf32_Addr *) (l->l_addr + l->l_info[DT_PLTGOT]->d_un.d_ptr);
84 got[1] = (Elf32_Addr) l; /* Identify this shared object. */
85
86 /* The got[2] entry contains the address of a function which gets
87 called to get the address of a so far unresolved function and
88 jump to it. The profiling extension of the dynamic linker allows
89 to intercept the calls to collect information. In this case we
90 don't store the address in the GOT so that all future calls also
91 end in this function. */
92 if (profile)
93 {
94 got[2] = (Elf32_Addr) &_dl_runtime_profile;
95 /* Say that we really want profiling and the timers are started. */
96 _dl_profile_map = l;
97 }
98 else
99 /* This function will get called to fix up the GOT entry indicated by
100 the offset on the stack, and then jump to the resolved address. */
101 got[2] = (Elf32_Addr) &_dl_runtime_resolve;
102 }
103
104 return lazy;
105 }
106
107 /* This code is used in dl-runtime.c to call the `fixup' function
108 and then redirect to the address it returns. */
109 #define TRAMPOLINE_TEMPLATE(tramp_name, fixup_name) \
110 "| Trampoline for " #fixup_name "
111 .globl " #tramp_name "
112 .type " #tramp_name ", @function
113 " #tramp_name ":
114 | Save %a0 (struct return address) and %a1.
115 move.l %a0, -(%sp)
116 move.l %a1, -(%sp)
117 | Call the real address resolver.
118 jbsr " #fixup_name "
119 | Restore register %a0 and %a1.
120 move.l (%sp)+, %a1
121 move.l (%sp)+, %a0
122 | Pop parameters
123 addq.l #8, %sp
124 | Call real function.
125 jmp (%d0)
126 .size " #tramp_name ", . - " #tramp_name "\n"
127 #ifndef PROF
128 #define ELF_MACHINE_RUNTIME_TRAMPOLINE \
129 asm (TRAMPOLINE_TEMPLATE (_dl_runtime_resolve, fixup) \
130 TRAMPOLINE_TEMPLATE (_dl_runtime_profile, profile_fixup));
131 #else
132 #define ELF_MACHINE_RUNTIME_TRAMPOLINE \
133 asm (TRAMPOLINE_TEMPLATE (_dl_runtime_resolve, fixup) \
134 ".globl _dl_runtime_profile\n" \
135 ".set _dl_runtime_profile, _dl_runtime_resolve");
136 #endif
137 #define ELF_MACHINE_RUNTIME_FIXUP_ARGS long int save_a0, long int save_a1
138 /* The PLT uses Elf32_Rela relocs. */
139 #define elf_machine_relplt elf_machine_rela
140
141
142 /* Mask identifying addresses reserved for the user program,
143 where the dynamic linker should not map anything. */
144 #define ELF_MACHINE_USER_ADDRESS_MASK 0x80000000UL
145
146 /* Initial entry point code for the dynamic linker.
147 The C function `_dl_start' is the real entry point;
148 its return value is the user program's entry point. */
149
150 #define RTLD_START asm ("\
151 .text
152 .globl _start
153 .type _start,@function
154 _start:
155 move.l %sp, -(%sp)
156 jbsr _dl_start
157 addq.l #4, %sp
158
159 .globl _dl_start_user
160 .type _dl_start_user,@function
161 _dl_start_user:
162 | Save the user entry point address in %a4.
163 move.l %d0, %a4
164 | Point %a5 at the GOT.
165 lea _GLOBAL_OFFSET_TABLE_@GOTPC(%pc), %a5
166 | See if we were run as a command with the executable file
167 | name as an extra leading argument.
168 move.l ([_dl_skip_args@GOT, %a5]), %d0
169 jeq 0f
170 | Pop the original argument count
171 move.l (%sp)+, %d1
172 | Subtract _dl_skip_args from it.
173 sub.l %d0, %d1
174 | Adjust the stack pointer to skip _dl_skip_args words.
175 lea (%sp, %d0*4), %sp
176 | Push back the modified argument count.
177 move.l %d1, -(%sp)
178 0: | Push _dl_default_scope[2] as argument in _dl_init_next call below.
179 move.l ([_dl_default_scope@GOT, %a5], 8), %d2
180 0: move.l %d2, -(%sp)
181 | Call _dl_init_next to return the address of an initializer
182 | function to run.
183 bsr.l _dl_init_next@PLTPC
184 add.l #4, %sp | Pop argument.
185 | Check for zero return, when out of initializers.
186 tst.l %d0
187 jeq 1f
188 | Call the shared object initializer function.
189 | NOTE: We depend only on the registers (%d2, %a4 and %a5)
190 | and the return address pushed by this call;
191 | the initializer is called with the stack just
192 | as it appears on entry, and it is free to move
193 | the stack around, as long as it winds up jumping to
194 | the return address on the top of the stack.
195 move.l %d0, %a0
196 jsr (%a0)
197 | Loop to call _dl_init_next for the next initializer.
198 jra 0b
199 1: | Clear the startup flag.
200 clr.l _dl_starting_up@GOT(%a5)
201 | Pass our finalizer function to the user in %a1.
202 move.l _dl_fini@GOT(%a5), %a1
203 | Initialize %fp with the stack pointer.
204 move.l %sp, %fp
205 | Jump to the user's entry point.
206 jmp (%a4)
207 .size _dl_start_user, . - _dl_start_user
208 .previous");
209
210 /* Nonzero iff TYPE describes a relocation that should
211 skip the executable when looking up the symbol value. */
212 #define elf_machine_lookup_noexec_p(type) ((type) == R_68K_COPY)
213
214 /* Nonzero iff TYPE describes relocation of a PLT entry, so
215 PLT entries should not be allowed to define the value. */
216 #define elf_machine_lookup_noplt_p(type) ((type) == R_68K_JMP_SLOT)
217
218 /* A reloc type used for ld.so cmdline arg lookups to reject PLT entries. */
219 #define ELF_MACHINE_RELOC_NOPLT R_68K_JMP_SLOT
220
221 /* The m68k never uses Elf32_Rel relocations. */
222 #define ELF_MACHINE_NO_REL 1
223
224 #endif /* !dl_machine_h */
225
226 #ifdef RESOLVE
227
228 /* Perform the relocation specified by RELOC and SYM (which is fully resolved).
229 MAP is the object containing the reloc. */
230
231 static inline void
232 elf_machine_rela (struct link_map *map, const Elf32_Rela *reloc,
233 const Elf32_Sym *sym, const struct r_found_version *version,
234 Elf32_Addr *const reloc_addr)
235 {
236 if (ELF32_R_TYPE (reloc->r_info) == R_68K_RELATIVE)
237 *reloc_addr = map->l_addr + reloc->r_addend;
238 else
239 {
240 const Elf32_Sym *const refsym = sym;
241 Elf32_Addr value = RESOLVE (&sym, version, ELF32_R_TYPE (reloc->r_info));
242 if (sym)
243 value += sym->st_value;
244
245 switch (ELF32_R_TYPE (reloc->r_info))
246 {
247 case R_68K_COPY:
248 if (sym == NULL)
249 /* This can happen in trace mode if an object could not be
250 found. */
251 break;
252 if (sym->st_size > refsym->st_size
253 || (_dl_verbose && sym->st_size < refsym->st_size))
254 {
255 extern char **_dl_argv;
256 const char *strtab;
257
258 strtab = ((void *) map->l_addr
259 + map->l_info[DT_STRTAB]->d_un.d_ptr);
260 _dl_sysdep_error (_dl_argv[0] ?: "<program name unknown>",
261 ": Symbol `", strtab + refsym->st_name,
262 "' has different size in shared object, "
263 "consider re-linking\n", NULL);
264 }
265 memcpy (reloc_addr, (void *) value, MIN (sym->st_size,
266 refsym->st_size));
267 break;
268 case R_68K_GLOB_DAT:
269 case R_68K_JMP_SLOT:
270 *reloc_addr = value;
271 break;
272 case R_68K_8:
273 *(char *) reloc_addr = value + reloc->r_addend;
274 break;
275 case R_68K_16:
276 *(short *) reloc_addr = value + reloc->r_addend;
277 break;
278 case R_68K_32:
279 *reloc_addr = value + reloc->r_addend;
280 break;
281 case R_68K_PC8:
282 *(char *) reloc_addr
283 = value + reloc->r_addend - (Elf32_Addr) reloc_addr;
284 break;
285 case R_68K_PC16:
286 *(short *) reloc_addr
287 = value + reloc->r_addend - (Elf32_Addr) reloc_addr;
288 break;
289 case R_68K_PC32:
290 *reloc_addr = value + reloc->r_addend - (Elf32_Addr) reloc_addr;
291 break;
292 case R_68K_NONE: /* Alright, Wilbur. */
293 break;
294 default:
295 assert (! "unexpected dynamic reloc type");
296 break;
297 }
298 }
299 }
300
301 static inline void
302 elf_machine_lazy_rel (struct link_map *map, const Elf32_Rela *reloc)
303 {
304 Elf32_Addr *const reloc_addr = (void *) (map->l_addr + reloc->r_offset);
305 switch (ELF32_R_TYPE (reloc->r_info))
306 {
307 case R_68K_JMP_SLOT:
308 *reloc_addr += map->l_addr;
309 break;
310 default:
311 assert (! "unexpected PLT reloc type");
312 break;
313 }
314 }
315
316 #endif /* RESOLVE */
This page took 0.050332 seconds and 5 git commands to generate.