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 (".Lhere: lea .Lhere(%%pc), %0\n"
65 /* The `subl' insn above will contain an R_68K_RELATIVE relocation
66 entry intended to insert the run-time address of the label `.Lhere'.
67 This will be the first relocation in the text of the dynamic
68 linker; we skip it to avoid trying to modify read-only text in this
70 #define ELF_MACHINE_BEFORE_RTLD_RELOC(dynamic_info) \
71 ((dynamic_info)[DT_RELA]->d_un.d_ptr += sizeof (Elf32_Rela), \
72 (dynamic_info)[DT_RELASZ]->d_un.d_val -= sizeof (Elf32_Rela))
75 /* Set up the loaded object described by L so its unrelocated PLT
76 entries will jump to the on-demand fixup code in dl-runtime.c. */
79 elf_machine_runtime_setup (struct link_map
*l
, int lazy
, int profile
)
82 extern void _dl_runtime_resolve (Elf32_Word
);
83 extern void _dl_runtime_profile (Elf32_Word
);
85 if (l
->l_info
[DT_JMPREL
] && lazy
)
87 /* The GOT entries for functions in the PLT have not yet been
88 filled in. Their initial contents will arrange when called
89 to push an offset into the .rela.plt section, push
90 _GLOBAL_OFFSET_TABLE_[1], and then jump to
91 _GLOBAL_OFFSET_TABLE_[2]. */
92 got
= (Elf32_Addr
*) (l
->l_addr
+ l
->l_info
[DT_PLTGOT
]->d_un
.d_ptr
);
93 got
[1] = (Elf32_Addr
) l
; /* Identify this shared object. */
95 /* The got[2] entry contains the address of a function which gets
96 called to get the address of a so far unresolved function and
97 jump to it. The profiling extension of the dynamic linker allows
98 to intercept the calls to collect information. In this case we
99 don't store the address in the GOT so that all future calls also
100 end in this function. */
103 got
[2] = (Elf32_Addr
) &_dl_runtime_profile
;
104 /* Say that we really want profiling and the timers are started. */
108 /* This function will get called to fix up the GOT entry indicated by
109 the offset on the stack, and then jump to the resolved address. */
110 got
[2] = (Elf32_Addr
) &_dl_runtime_resolve
;
116 /* This code is used in dl-runtime.c to call the `fixup' function
117 and then redirect to the address it returns. */
118 #define TRAMPOLINE_TEMPLATE(tramp_name, fixup_name) \
119 "| Trampoline for " #fixup_name "
120 .globl " #tramp_name "
121 .type " #tramp_name ", @function
123 | Save %a0 (struct return address) and %a1.
126 | Call the real address resolver.
128 | Restore register %a0 and %a1.
133 | Call real function.
135 .size " #tramp_name ", . - " #tramp_name "\n"
137 #define ELF_MACHINE_RUNTIME_TRAMPOLINE \
138 asm (TRAMPOLINE_TEMPLATE (_dl_runtime_resolve, fixup) \
139 TRAMPOLINE_TEMPLATE (_dl_runtime_profile, profile_fixup));
141 #define ELF_MACHINE_RUNTIME_TRAMPOLINE \
142 asm (TRAMPOLINE_TEMPLATE (_dl_runtime_resolve, fixup) \
143 ".globl _dl_runtime_profile\n" \
144 ".set _dl_runtime_profile, _dl_runtime_resolve");
146 #define ELF_MACHINE_RUNTIME_FIXUP_ARGS long int save_a0, long int save_a1
147 /* The PLT uses Elf32_Rela relocs. */
148 #define elf_machine_relplt elf_machine_rela
151 /* Mask identifying addresses reserved for the user program,
152 where the dynamic linker should not map anything. */
153 #define ELF_MACHINE_USER_ADDRESS_MASK 0x80000000UL
155 /* Initial entry point code for the dynamic linker.
156 The C function `_dl_start' is the real entry point;
157 its return value is the user program's entry point. */
159 #define RTLD_START asm ("\
162 .globl _dl_start_user
168 | Save the user entry point address in %a4.
170 | Point %a5 at the GOT.
171 lea _GLOBAL_OFFSET_TABLE_@GOTPC(%pc), %a5
172 | See if we were run as a command with the executable file
173 | name as an extra leading argument.
174 move.l ([_dl_skip_args@GOT, %a5]), %d0
176 | Pop the original argument count
178 | Subtract _dl_skip_args from it.
180 | Adjust the stack pointer to skip _dl_skip_args words.
181 lea (%sp, %d0*4), %sp
182 | Push back the modified argument count.
184 0: | Push _dl_default_scope[2] as argument in _dl_init_next call below.
185 move.l ([_dl_default_scope@GOT, %a5], 8), %d2
186 0: move.l %d2, -(%sp)
187 | Call _dl_init_next to return the address of an initializer
189 bsr.l _dl_init_next@PLTPC
190 add.l #4, %sp | Pop argument.
191 | Check for zero return, when out of initializers.
194 | Call the shared object initializer function.
195 | NOTE: We depend only on the registers (%d2, %a4 and %a5)
196 | and the return address pushed by this call;
197 | the initializer is called with the stack just
198 | as it appears on entry, and it is free to move
199 | the stack around, as long as it winds up jumping to
200 | the return address on the top of the stack.
203 | Loop to call _dl_init_next for the next initializer.
205 1: | Clear the startup flag.
206 clr.l _dl_starting_up@GOT(%a5)
207 | Pass our finalizer function to the user in %a1.
208 move.l _dl_fini@GOT(%a5), %a1
209 | Initialize %fp with the stack pointer.
211 | Jump to the user's entry point.
214 /* Nonzero iff TYPE describes a relocation that should
215 skip the executable when looking up the symbol value. */
216 #define elf_machine_lookup_noexec_p(type) ((type) == R_68K_COPY)
218 /* Nonzero iff TYPE describes relocation of a PLT entry, so
219 PLT entries should not be allowed to define the value. */
220 #define elf_machine_lookup_noplt_p(type) ((type) == R_68K_JMP_SLOT)
222 /* A reloc type used for ld.so cmdline arg lookups to reject PLT entries. */
223 #define ELF_MACHINE_RELOC_NOPLT R_68K_JMP_SLOT
225 /* The m68k never uses Elf32_Rel relocations. */
226 #define ELF_MACHINE_NO_REL 1
228 #endif /* !dl_machine_h */
232 /* Perform the relocation specified by RELOC and SYM (which is fully resolved).
233 MAP is the object containing the reloc. */
236 elf_machine_rela (struct link_map
*map
, const Elf32_Rela
*reloc
,
237 const Elf32_Sym
*sym
, const struct r_found_version
*version
,
238 Elf32_Addr
*const reloc_addr
)
240 if (ELF32_R_TYPE (reloc
->r_info
) == R_68K_RELATIVE
)
241 *reloc_addr
= map
->l_addr
+ reloc
->r_addend
;
244 const Elf32_Sym
*const refsym
= sym
;
245 Elf32_Addr value
= RESOLVE (&sym
, version
, ELF32_R_TYPE (reloc
->r_info
));
247 value
+= sym
->st_value
;
249 switch (ELF32_R_TYPE (reloc
->r_info
))
253 /* This can happen in trace mode if an object could not be
256 if (sym
->st_size
> refsym
->st_size
257 || (_dl_verbose
&& sym
->st_size
< refsym
->st_size
))
259 extern char **_dl_argv
;
262 strtab
= ((void *) map
->l_addr
263 + map
->l_info
[DT_STRTAB
]->d_un
.d_ptr
);
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 assert (! "unexpected dynamic reloc type");
306 elf_machine_lazy_rel (struct link_map
*map
, const Elf32_Rela
*reloc
)
308 Elf32_Addr
*const reloc_addr
= (void *) (map
->l_addr
+ reloc
->r_offset
);
309 switch (ELF32_R_TYPE (reloc
->r_info
))
312 *reloc_addr
+= map
->l_addr
;
315 assert (! "unexpected PLT reloc type");