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
)
82 extern void _dl_runtime_resolve (Elf32_Word
);
84 if (l
->l_info
[DT_JMPREL
] && lazy
)
86 /* The GOT entries for functions in the PLT have not yet been
87 filled in. Their initial contents will arrange when called
88 to push an offset into the .rela.plt section, push
89 _GLOBAL_OFFSET_TABLE_[1], and then jump to
90 _GLOBAL_OFFSET_TABLE_[2]. */
91 got
= (Elf32_Addr
*) (l
->l_addr
+ l
->l_info
[DT_PLTGOT
]->d_un
.d_ptr
);
92 got
[1] = (Elf32_Addr
) l
; /* Identify this shared object. */
93 /* This function will get called to fix up the GOT entry
94 indicated by the offset on the stack, and then jump to the
96 got
[2] = (Elf32_Addr
) &_dl_runtime_resolve
;
102 /* This code is used in dl-runtime.c to call the `fixup' function
103 and then redirect to the address it returns. */
104 #define ELF_MACHINE_RUNTIME_TRAMPOLINE asm ("\
105 | Trampoline for _dl_runtime_resolver
106 .globl _dl_runtime_resolve
107 .type _dl_runtime_resolve, @function
109 | Save %a0 (struct return address) and %a1.
112 | Call the real address resolver.
114 | Restore register %a0 and %a1.
119 | Call real function.
121 .size _dl_runtime_resolve, . - _dl_runtime_resolve
123 #define ELF_MACHINE_RUNTIME_FIXUP_ARGS long int save_a0, long int save_a1
124 /* The PLT uses Elf32_Rela relocs. */
125 #define elf_machine_relplt elf_machine_rela
128 /* Mask identifying addresses reserved for the user program,
129 where the dynamic linker should not map anything. */
130 #define ELF_MACHINE_USER_ADDRESS_MASK 0x80000000UL
132 /* Initial entry point code for the dynamic linker.
133 The C function `_dl_start' is the real entry point;
134 its return value is the user program's entry point. */
136 #define RTLD_START asm ("\
139 .globl _dl_start_user
145 | Save the user entry point address in %a4.
147 | Point %a5 at the GOT.
148 lea _GLOBAL_OFFSET_TABLE_@GOTPC(%pc), %a5
149 | See if we were run as a command with the executable file
150 | name as an extra leading argument.
151 move.l ([_dl_skip_args@GOT, %a5]), %d0
153 | Pop the original argument count
155 | Subtract _dl_skip_args from it.
157 | Adjust the stack pointer to skip _dl_skip_args words.
158 lea (%sp, %d0*4), %sp
159 | Push back the modified argument count.
161 0: | Push _dl_default_scope[2] as argument in _dl_init_next call below.
162 move.l ([_dl_default_scope@GOT, %a5], 8), %d2
163 0: move.l %d2, -(%sp)
164 | Call _dl_init_next to return the address of an initializer
166 bsr.l _dl_init_next@PLTPC
167 add.l #4, %sp | Pop argument.
168 | Check for zero return, when out of initializers.
171 | Call the shared object initializer function.
172 | NOTE: We depend only on the registers (%d2, %a4 and %a5)
173 | and the return address pushed by this call;
174 | the initializer is called with the stack just
175 | as it appears on entry, and it is free to move
176 | the stack around, as long as it winds up jumping to
177 | the return address on the top of the stack.
180 | Loop to call _dl_init_next for the next initializer.
182 1: | Clear the startup flag.
183 clr.l _dl_starting_up@GOT(%a5)
184 | Pass our finalizer function to the user in %a1.
185 move.l _dl_fini@GOT(%a5), %a1
186 | Initialize %fp with the stack pointer.
188 | Jump to the user's entry point.
191 /* Nonzero iff TYPE describes a relocation that should
192 skip the executable when looking up the symbol value. */
193 #define elf_machine_lookup_noexec_p(type) ((type) == R_68K_COPY)
195 /* Nonzero iff TYPE describes relocation of a PLT entry, so
196 PLT entries should not be allowed to define the value. */
197 #define elf_machine_lookup_noplt_p(type) ((type) == R_68K_JMP_SLOT)
199 /* A reloc type used for ld.so cmdline arg lookups to reject PLT entries. */
200 #define ELF_MACHINE_RELOC_NOPLT R_68K_JMP_SLOT
202 /* The m68k never uses Elf32_Rel relocations. */
203 #define ELF_MACHINE_NO_REL 1
205 #endif /* !dl_machine_h */
209 /* Perform the relocation specified by RELOC and SYM (which is fully resolved).
210 MAP is the object containing the reloc. */
213 elf_machine_rela (struct link_map
*map
, const Elf32_Rela
*reloc
,
214 const Elf32_Sym
*sym
, const struct r_found_version
*version
)
216 Elf32_Addr
*const reloc_addr
= (void *) (map
->l_addr
+ reloc
->r_offset
);
218 if (ELF32_R_TYPE (reloc
->r_info
) == R_68K_RELATIVE
)
219 *reloc_addr
= map
->l_addr
+ reloc
->r_addend
;
222 const Elf32_Sym
*const refsym
= sym
;
223 Elf32_Addr value
= RESOLVE (&sym
, version
, ELF32_R_TYPE (reloc
->r_info
));
225 value
+= sym
->st_value
;
227 switch (ELF32_R_TYPE (reloc
->r_info
))
231 /* This can happen in trace mode if an object could not be
234 if (sym
->st_size
> refsym
->st_size
235 || (_dl_verbose
&& sym
->st_size
< refsym
->st_size
))
237 extern char **_dl_argv
;
240 strtab
= ((void *) map
->l_addr
241 + map
->l_info
[DT_STRTAB
]->d_un
.d_ptr
);
242 _dl_sysdep_error (_dl_argv
[0] ?: "<program name unknown>",
243 ": Symbol `", strtab
+ refsym
->st_name
,
244 "' has different size in shared object, "
245 "consider re-linking\n", NULL
);
247 memcpy (reloc_addr
, (void *) value
, MIN (sym
->st_size
,
255 *(char *) reloc_addr
= value
+ reloc
->r_addend
;
258 *(short *) reloc_addr
= value
+ reloc
->r_addend
;
261 *reloc_addr
= value
+ reloc
->r_addend
;
265 = value
+ reloc
->r_addend
- (Elf32_Addr
) reloc_addr
;
268 *(short *) reloc_addr
269 = value
+ reloc
->r_addend
- (Elf32_Addr
) reloc_addr
;
272 *reloc_addr
= value
+ reloc
->r_addend
- (Elf32_Addr
) reloc_addr
;
274 case R_68K_NONE
: /* Alright, Wilbur. */
277 assert (! "unexpected dynamic reloc type");
284 elf_machine_lazy_rel (struct link_map
*map
, const Elf32_Rela
*reloc
)
286 Elf32_Addr
*const reloc_addr
= (void *) (map
->l_addr
+ reloc
->r_offset
);
287 switch (ELF32_R_TYPE (reloc
->r_info
))
290 *reloc_addr
+= map
->l_addr
;
293 assert (! "unexpected PLT reloc type");