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