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"
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 ("here: lea here(%%pc), %0\n"
63 /* The `subl' insn above will contain an R_68K_RELATIVE relocation
64 entry intended to insert the run-time address of the label `here'.
65 This will be the first relocation in the text of the dynamic
66 linker; we skip it to avoid trying to modify read-only text in this
68 #define ELF_MACHINE_BEFORE_RTLD_RELOC(dynamic_info) \
69 ((dynamic_info)[DT_RELA]->d_un.d_ptr += sizeof (Elf32_Rela), \
70 (dynamic_info)[DT_RELASZ]->d_un.d_val -= sizeof (Elf32_Rela))
73 /* Set up the loaded object described by L so its unrelocated PLT
74 entries will jump to the on-demand fixup code in dl-runtime.c. */
77 elf_machine_runtime_setup (struct link_map
*l
, int lazy
)
80 extern void _dl_runtime_resolve (Elf32_Word
);
82 if (l
->l_info
[DT_JMPREL
] && lazy
)
84 /* The GOT entries for functions in the PLT have not yet been
85 filled in. Their initial contents will arrange when called
86 to push an offset into the .rela.plt section, push
87 _GLOBAL_OFFSET_TABLE_[1], and then jump to
88 _GLOBAL_OFFSET_TABLE_[2]. */
89 got
= (Elf32_Addr
*) (l
->l_addr
+ l
->l_info
[DT_PLTGOT
]->d_un
.d_ptr
);
90 got
[1] = (Elf32_Addr
) l
; /* Identify this shared object. */
91 /* This function will get called to fix up the GOT entry
92 indicated by the offset on the stack, and then jump to the
94 got
[2] = (Elf32_Addr
) &_dl_runtime_resolve
;
99 /* This code is used in dl-runtime.c to call the `fixup' function
100 and then redirect to the address it returns. */
101 #define ELF_MACHINE_RUNTIME_TRAMPOLINE asm ("\
102 | Trampoline for _dl_runtime_resolver
103 .globl _dl_runtime_resolve
104 .type _dl_runtime_resolve, @function
106 | Save %a0 (struct return address) and %a1.
109 | Call the real address resolver.
111 | Restore register %a0 and %a1.
116 | Call real function.
118 .size _dl_runtime_resolve, . - _dl_runtime_resolve
120 #define ELF_MACHINE_RUNTIME_FIXUP_ARGS long int save_a0, long int save_a1
121 /* The PLT uses Elf32_Rela relocs. */
122 #define elf_machine_relplt elf_machine_rela
125 /* Mask identifying addresses reserved for the user program,
126 where the dynamic linker should not map anything. */
127 #define ELF_MACHINE_USER_ADDRESS_MASK 0x80000000UL
129 /* Initial entry point code for the dynamic linker.
130 The C function `_dl_start' is the real entry point;
131 its return value is the user program's entry point. */
133 #define RTLD_START asm ("\
136 .globl _dl_start_user
142 | Save the user entry point address in %a4.
144 | Point %a5 at the GOT.
145 lea _GLOBAL_OFFSET_TABLE_@GOTPC(%pc), %a5
146 | See if we were run as a command with the executable file
147 | name as an extra leading argument.
148 move.l ([_dl_skip_args@GOT, %a5]), %d0
150 | Pop the original argument count
152 | Subtract _dl_skip_args from it.
154 | Adjust the stack pointer to skip _dl_skip_args words.
155 lea (%sp, %d0*4), %sp
156 | Push back the modified argument count.
158 0: | Push _dl_default_scope[2] as argument in _dl_init_next call below.
159 move.l ([_dl_default_scope@GOT, %a5], 8), %d2
160 0: move.l %d2, -(%sp)
161 | Call _dl_init_next to return the address of an initializer
163 bsr.l _dl_init_next@PLTPC
164 add.l #4, %sp | Pop argument.
165 | Check for zero return, when out of initializers.
168 | Call the shared object initializer function.
169 | NOTE: We depend only on the registers (%d2, %a4 and %a5)
170 | and the return address pushed by this call;
171 | the initializer is called with the stack just
172 | as it appears on entry, and it is free to move
173 | the stack around, as long as it winds up jumping to
174 | the return address on the top of the stack.
177 | Loop to call _dl_init_next for the next initializer.
179 1: | Clear the startup flag.
180 clr.l _dl_starting_up@GOT(%a5)
181 | Pass our finalizer function to the user in %a1.
182 move.l _dl_fini@GOT(%a5), %a1
183 | Initialize %fp with the stack pointer.
185 | Jump to the user's entry point.
188 /* Nonzero iff TYPE describes relocation of a PLT entry, so
189 PLT entries should not be allowed to define the value. */
190 #define elf_machine_pltrel_p(type) ((type) == R_68K_JMP_SLOT)
192 /* The m68k never uses Elf32_Rel relocations. */
193 #define ELF_MACHINE_NO_REL 1
195 #endif /* !dl_machine_h */
199 /* Perform the relocation specified by RELOC and SYM (which is fully resolved).
200 MAP is the object containing the reloc. */
203 elf_machine_rela (struct link_map
*map
,
204 const Elf32_Rela
*reloc
, const Elf32_Sym
*sym
)
206 Elf32_Addr
*const reloc_addr
= (void *) (map
->l_addr
+ reloc
->r_offset
);
209 switch (ELF32_R_TYPE (reloc
->r_info
))
212 loadbase
= RESOLVE (&sym
, DL_LOOKUP_NOEXEC
);
213 memcpy (reloc_addr
, (void *) (loadbase
+ sym
->st_value
), sym
->st_size
);
216 loadbase
= RESOLVE (&sym
, 0);
217 *reloc_addr
= sym
? (loadbase
+ sym
->st_value
) : 0;
220 loadbase
= RESOLVE (&sym
, DL_LOOKUP_NOPLT
);
221 *reloc_addr
= sym
? (loadbase
+ sym
->st_value
) : 0;
224 loadbase
= RESOLVE (&sym
, 0);
225 *(char *) reloc_addr
= ((sym
? (loadbase
+ sym
->st_value
) : 0)
229 loadbase
= RESOLVE (&sym
, 0);
230 *(short *) reloc_addr
= ((sym
? (loadbase
+ sym
->st_value
) : 0)
234 loadbase
= RESOLVE (&sym
, 0);
235 *reloc_addr
= ((sym
? (loadbase
+ sym
->st_value
) : 0)
239 *reloc_addr
= map
->l_addr
+ reloc
->r_addend
;
242 loadbase
= RESOLVE (&sym
, 0);
243 *(char *) reloc_addr
= ((sym
? (loadbase
+ sym
->st_value
) : 0)
244 + reloc
->r_addend
- (Elf32_Addr
) reloc_addr
);
247 loadbase
= RESOLVE (&sym
, 0);
248 *(short *) reloc_addr
= ((sym
? (loadbase
+ sym
->st_value
) : 0)
249 + reloc
->r_addend
- (Elf32_Addr
) reloc_addr
);
252 loadbase
= RESOLVE (&sym
, 0);
253 *reloc_addr
= ((sym
? (loadbase
+ sym
->st_value
) : 0)
254 + reloc
->r_addend
- (Elf32_Addr
) reloc_addr
);
256 case R_68K_NONE
: /* Alright, Wilbur. */
259 assert (! "unexpected dynamic reloc type");
265 elf_machine_lazy_rel (struct link_map
*map
, const Elf32_Rela
*reloc
)
267 Elf32_Addr
*const reloc_addr
= (void *) (map
->l_addr
+ reloc
->r_offset
);
268 switch (ELF32_R_TYPE (reloc
->r_info
))
271 *reloc_addr
+= map
->l_addr
;
274 assert (! "unexpected PLT reloc type");