]>
sourceware.org Git - glibc.git/blob - 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.
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. */
23 #define ELF_MACHINE_NAME "m68k"
25 #include <sys/param.h>
29 /* Return nonzero iff E_MACHINE is compatible with the running host. */
31 elf_machine_matches_host (Elf32_Half e_machine
)
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 ("%a5");
54 /* Return the run-time load address of the shared object. */
55 static inline Elf32_Addr
56 elf_machine_load_address (void)
59 asm ("1: lea 1b(%%pc), %0\n"
60 " sub.l 1b@GOTPC(%%pc), %0"
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. */
70 elf_machine_runtime_setup (struct link_map
*l
, int lazy
, int profile
)
73 extern void _dl_runtime_resolve (Elf32_Word
);
74 extern void _dl_runtime_profile (Elf32_Word
);
76 if (l
->l_info
[DT_JMPREL
] && lazy
)
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. */
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. */
94 got
[2] = (Elf32_Addr
) &_dl_runtime_profile
;
95 /* Say that we really want profiling and the timers are started. */
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
;
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
114 | Save %a0 (struct return address) and %a1.
117 | Call the real address resolver.
119 | Restore register %a0 and %a1.
124 | Call real function.
126 .size " #tramp_name ", . - " #tramp_name "\n"
128 #define ELF_MACHINE_RUNTIME_TRAMPOLINE \
129 asm (TRAMPOLINE_TEMPLATE (_dl_runtime_resolve, fixup) \
130 TRAMPOLINE_TEMPLATE (_dl_runtime_profile, profile_fixup));
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");
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
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
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. */
150 #define RTLD_START asm ("\
153 .type _start,@function
159 .globl _dl_start_user
160 .type _dl_start_user,@function
162 | Save the user entry point address in %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
170 | Pop the original argument count
172 | Subtract _dl_skip_args from it.
174 | Adjust the stack pointer to skip _dl_skip_args words.
175 lea (%sp, %d0*4), %sp
176 | Push back the modified argument count.
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
183 bsr.l _dl_init_next@PLTPC
184 add.l #4, %sp | Pop argument.
185 | Check for zero return, when out of initializers.
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.
197 | Loop to call _dl_init_next for the next initializer.
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.
205 | Jump to the user's entry point.
207 .size _dl_start_user, . - _dl_start_user
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)
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)
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
221 /* The m68k never uses Elf32_Rel relocations. */
222 #define ELF_MACHINE_NO_REL 1
224 #endif /* !dl_machine_h */
228 /* Perform the relocation specified by RELOC and SYM (which is fully resolved).
229 MAP is the object containing the reloc. */
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
)
236 if (ELF32_R_TYPE (reloc
->r_info
) == R_68K_RELATIVE
)
237 *reloc_addr
= map
->l_addr
+ reloc
->r_addend
;
240 const Elf32_Sym
*const refsym
= sym
;
241 Elf32_Addr value
= RESOLVE (&sym
, version
, ELF32_R_TYPE (reloc
->r_info
));
243 value
+= sym
->st_value
;
245 switch (ELF32_R_TYPE (reloc
->r_info
))
249 /* This can happen in trace mode if an object could not be
252 if (sym
->st_size
> refsym
->st_size
253 || (_dl_verbose
&& sym
->st_size
< refsym
->st_size
))
255 extern char **_dl_argv
;
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
);
265 memcpy (reloc_addr
, (void *) value
, MIN (sym
->st_size
,
273 *(char *) reloc_addr
= value
+ reloc
->r_addend
;
276 *(short *) reloc_addr
= value
+ reloc
->r_addend
;
279 *reloc_addr
= value
+ reloc
->r_addend
;
283 = value
+ reloc
->r_addend
- (Elf32_Addr
) reloc_addr
;
286 *(short *) reloc_addr
287 = value
+ reloc
->r_addend
- (Elf32_Addr
) reloc_addr
;
290 *reloc_addr
= value
+ reloc
->r_addend
- (Elf32_Addr
) reloc_addr
;
292 case R_68K_NONE
: /* Alright, Wilbur. */
295 assert (! "unexpected dynamic reloc type");
302 elf_machine_lazy_rel (struct link_map
*map
, const Elf32_Rela
*reloc
)
304 Elf32_Addr
*const reloc_addr
= (void *) (map
->l_addr
+ reloc
->r_offset
);
305 switch (ELF32_R_TYPE (reloc
->r_info
))
308 *reloc_addr
+= map
->l_addr
;
311 assert (! "unexpected PLT reloc type");
This page took 0.050332 seconds and 5 git commands to generate.