1 /* Machine-dependent ELF dynamic relocation inline functions. m68k version.
2 Copyright (C) 1996 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., 675 Mass Ave,
18 Cambridge, MA 02139, USA. */
20 #define ELF_MACHINE_NAME "m68k"
27 /* Return nonzero iff E_MACHINE is compatible with the running host. */
29 elf_machine_matches_host (Elf32_Half e_machine)
41 /* Return the run-time address of the _GLOBAL_OFFSET_TABLE_.
42 Must be inlined in a function which uses global data. */
43 static inline Elf32_Addr *
44 elf_machine_got (void)
46 register Elf32_Addr *got asm ("%a5");
51 /* Return the run-time load address of the shared object. */
52 static inline Elf32_Addr
53 elf_machine_load_address (void)
56 asm ("here: lea here(%%pc), %0\n"
62 /* The `subl' insn above will contain an R_68K_RELATIVE relocation
63 entry intended to insert the run-time address of the label `here'.
64 This will be the first relocation in the text of the dynamic
65 linker; we skip it to avoid trying to modify read-only text in this
67 #define ELF_MACHINE_BEFORE_RTLD_RELOC(dynamic_info) \
68 ((dynamic_info)[DT_RELA]->d_un.d_ptr += sizeof (Elf32_Rela), \
69 (dynamic_info)[DT_RELASZ]->d_un.d_val -= sizeof (Elf32_Rela))
71 /* Perform the relocation specified by RELOC and SYM (which is fully resolved).
72 MAP is the object containing the reloc. */
75 elf_machine_rela (struct link_map *map,
76 const Elf32_Rela *reloc,
77 Elf32_Addr sym_loadaddr, const Elf32_Sym *sym)
79 Elf32_Addr *const reloc_addr = (void *) (map->l_addr + reloc->r_offset);
80 const Elf32_Addr sym_value = sym ? sym_loadaddr + sym->st_value : 0;
82 switch (ELF32_R_TYPE (reloc->r_info))
85 memcpy (reloc_addr, (void *) sym_value, sym->st_size);
89 *reloc_addr = sym_value;
92 *(char *) reloc_addr = sym_value + reloc->r_addend;
95 *(short *) reloc_addr = sym_value + reloc->r_addend;
98 *reloc_addr = sym_value + reloc->r_addend;
101 *reloc_addr = map->l_addr + reloc->r_addend;
104 *(char *) reloc_addr = (sym_value + reloc->r_addend
105 - (Elf32_Addr) reloc_addr);
108 *(short *) reloc_addr = (sym_value + reloc->r_addend
109 - (Elf32_Addr) reloc_addr);
112 *reloc_addr = sym_value + reloc->r_addend - (Elf32_Addr) reloc_addr;
114 case R_68K_NONE: /* Alright, Wilbur. */
117 assert (! "unexpected dynamic reloc type");
123 elf_machine_lazy_rel (struct link_map *map, const Elf32_Rela *reloc)
125 Elf32_Addr *const reloc_addr = (void *) (map->l_addr + reloc->r_offset);
126 switch (ELF32_R_TYPE (reloc->r_info))
131 *reloc_addr += map->l_addr;
134 assert (! "unexpected PLT reloc type");
139 /* Nonzero iff TYPE describes relocation of a PLT entry, so
140 PLT entries should not be allowed to define the value. */
141 #define elf_machine_pltrel_p(type) ((type) == R_68K_JMP_SLOT)
143 /* The m68k never uses Elf32_Rel relocations. */
144 #define ELF_MACHINE_NO_REL 1
147 /* Set up the loaded object described by L so its unrelocated PLT
148 entries will jump to the on-demand fixup code in dl-runtime.c. */
151 elf_machine_runtime_setup (struct link_map *l, int lazy)
154 extern void _dl_runtime_resolve (Elf32_Word);
156 if (l->l_info[DT_JMPREL] && lazy)
158 /* The GOT entries for functions in the PLT have not yet been
159 filled in. Their initial contents will arrange when called
160 to push an offset into the .rela.plt section, push
161 _GLOBAL_OFFSET_TABLE_[1], and then jump to
162 _GLOBAL_OFFSET_TABLE_[2]. */
163 got = (Elf32_Addr *) (l->l_addr + l->l_info[DT_PLTGOT]->d_un.d_ptr);
164 got[1] = (Elf32_Addr) l; /* Identify this shared object. */
165 /* This function will get called to fix up the GOT entry
166 indicated by the offset on the stack, and then jump to the
168 got[2] = (Elf32_Addr) &_dl_runtime_resolve;
171 /* This code is used in dl-runtime.c to call the `fixup' function
172 and then redirect to the address it returns. */
173 #define ELF_MACHINE_RUNTIME_TRAMPOLINE asm ("\
174 | Trampoline for _dl_runtime_resolver
175 .globl _dl_runtime_resolve
176 .type _dl_runtime_resolve, @function
178 | Save %a0 (struct return address) and %a1.
181 | Call the real address resolver.
183 | Restore register %a0 and %a1.
188 | Call real function.
190 .size _dl_runtime_resolve, . - _dl_runtime_resolve
192 #define ELF_MACHINE_RUNTIME_FIXUP_ARGS long int save_a0, long int save_a1
193 /* The PLT uses Elf32_Rela relocs. */
194 #define elf_machine_relplt elf_machine_rela
198 /* Mask identifying addresses reserved for the user program,
199 where the dynamic linker should not map anything. */
200 #define ELF_MACHINE_USER_ADDRESS_MASK 0x80000000UL
202 /* Initial entry point code for the dynamic linker.
203 The C function `_dl_start' is the real entry point;
204 its return value is the user program's entry point. */
206 #define RTLD_START asm ("\
209 .globl _dl_start_user
213 | Save the user entry point address in %a4.
215 | Point %a5 at the GOT.
216 lea _GLOBAL_OFFSET_TABLE_@GOTPC(%pc), %a5
217 | See if we were run as a command with the executable file
218 | name as an extra leading argument.
219 move.l ([_dl_skip_args@GOT, %a5]), %d0
221 | Pop the original argument count
223 | Subtract _dl_skip_args from it.
225 | Adjust the stack pointer to skip _dl_skip_args words.
226 lea (%sp, %d0*4), %sp
227 | Push back the modified argument count.
229 | Call _dl_init_next to return the address of an initializer
231 0: bsr.l _dl_init_next@PLTPC
232 | Check for zero return, when out of initializers.
235 | Call the shared object initializer function.
236 | NOTE: We depend only on the registers (%a4 and %a5)
237 | and the return address pushed by this call;
238 | the initializer is called with the stack just
239 | as it appears on entry, and it is free to move
240 | the stack around, as long as it winds up jumping to
241 | the return address on the top of the stack.
244 | Loop to call _dl_init_next for the next initializer.
246 1: | Pass our finalizer function to the user in %a1.
247 move.l _dl_fini@GOT(%a5), %a1
248 | Initialize %fp with the stack pointer.
250 | Jump to the user's entry point.