]>
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, 1998, 1999, 2000 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>
27 /* Return nonzero iff E_MACHINE is compatible with the running host. */
29 elf_machine_matches_host (Elf32_Half e_machine
)
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
44 static inline Elf32_Addr
45 elf_machine_dynamic (void)
47 register Elf32_Addr
*got
asm ("%a5");
52 /* Return the run-time load address of the shared object. */
53 static inline Elf32_Addr
54 elf_machine_load_address (void)
57 asm ("lea _dl_start(%%pc), %0\n\t"
58 "sub.l _dl_start@GOT.w(%%a5), %0"
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. */
68 elf_machine_runtime_setup (struct link_map
*l
, int lazy
, int profile
)
71 extern void _dl_runtime_resolve (Elf32_Word
);
72 extern void _dl_runtime_profile (Elf32_Word
);
74 if (l
->l_info
[DT_JMPREL
] && lazy
)
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. */
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. */
92 got
[2] = (Elf32_Addr
) &_dl_runtime_profile
;
94 if (_dl_name_match_p (_dl_profile
, l
))
96 /* This is the object we are looking for. Say that we really
97 want profiling and the timers are started. */
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
;
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
117 | Save %a0 (struct return address) and %a1.
120 | Call the real address resolver.
122 | Restore register %a0 and %a1.
127 | Call real function.
129 .size " #tramp_name ", . - " #tramp_name "\n"
131 #define ELF_MACHINE_RUNTIME_TRAMPOLINE \
132 asm (TRAMPOLINE_TEMPLATE (_dl_runtime_resolve, fixup) \
133 TRAMPOLINE_TEMPLATE (_dl_runtime_profile, profile_fixup));
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");
140 #define ELF_MACHINE_RUNTIME_FIXUP_ARGS long int save_a0, long int save_a1
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
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. */
151 #define RTLD_START asm ("\
154 .type _start,@function
161 .globl _dl_start_user
162 .type _dl_start_user,@function
164 | Save the user entry point address in %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
175 | Subtract _dl_skip_args from it.
177 | Adjust the stack pointer to skip _dl_skip_args words.
178 lea (%sp, %d0*4), %sp
179 | Push back the modified argument count.
181 # Call _dl_init (struct link_map *main_map, int argc, char **argv, char **env)
185 move.l _dl_loaded@GOT.w(%a5), -(%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.
193 | Jump to the user's entry point.
195 .size _dl_start_user, . - _dl_start_user
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)
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)
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
209 /* The m68k never uses Elf32_Rel relocations. */
210 #define ELF_MACHINE_NO_REL 1
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
)
217 return *reloc_addr
= value
;
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
,
229 #endif /* !dl_machine_h */
233 /* Perform the relocation specified by RELOC and SYM (which is fully resolved).
234 MAP is the object containing the reloc. */
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
)
241 if (ELF32_R_TYPE (reloc
->r_info
) == R_68K_RELATIVE
)
242 *reloc_addr
= map
->l_addr
+ reloc
->r_addend
;
245 const Elf32_Sym
*const refsym
= sym
;
246 Elf32_Addr value
= RESOLVE (&sym
, version
, ELF32_R_TYPE (reloc
->r_info
));
248 value
+= sym
->st_value
;
250 switch (ELF32_R_TYPE (reloc
->r_info
))
254 /* This can happen in trace mode if an object could not be
257 if (sym
->st_size
> refsym
->st_size
258 || (sym
->st_size
< refsym
->st_size
&& _dl_verbose
))
260 extern char **_dl_argv
;
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
);
269 memcpy (reloc_addr
, (void *) value
, MIN (sym
->st_size
,
277 *(char *) reloc_addr
= value
+ reloc
->r_addend
;
280 *(short *) reloc_addr
= value
+ reloc
->r_addend
;
283 *reloc_addr
= value
+ reloc
->r_addend
;
287 = value
+ reloc
->r_addend
- (Elf32_Addr
) reloc_addr
;
290 *(short *) reloc_addr
291 = value
+ reloc
->r_addend
- (Elf32_Addr
) reloc_addr
;
294 *reloc_addr
= value
+ reloc
->r_addend
- (Elf32_Addr
) reloc_addr
;
296 case R_68K_NONE
: /* Alright, Wilbur. */
299 _dl_reloc_bad_type (map
, ELF32_R_TYPE (reloc
->r_info
), 0);
306 elf_machine_lazy_rel (struct link_map
*map
,
307 Elf32_Addr l_addr
, const Elf32_Rela
*reloc
)
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
;
313 _dl_reloc_bad_type (map
, ELF32_R_TYPE (reloc
->r_info
), 1);
This page took 0.063458 seconds and 5 git commands to generate.