static inline Elf32_Addr
elf_machine_load_address (void)
{
- ...
+ Elf32_Addr addr;
+ asm ("here: lea here(%%pc), %0\n"
+ " sub.l %#here, %0"
+ : "=a" (addr));
+ return addr;
}
+/* The `subl' insn above will contain an R_68K_RELATIVE relocation
+ entry intended to insert the run-time address of the label `here'.
+ This will be the first relocation in the text of the dynamic
+ linker; we skip it to avoid trying to modify read-only text in this
+ early stage. */
+#define ELF_MACHINE_BEFORE_RTLD_RELOC(dynamic_info) \
+ ((dynamic_info)[DT_RELA]->d_un.d_ptr += sizeof (Elf32_Rela), \
+ (dynamic_info)[DT_RELASZ]->d_un.d_val -= sizeof (Elf32_Rela))
+
/* Perform the relocation specified by RELOC and SYM (which is fully resolved).
MAP is the object containing the reloc. */
static inline void
elf_machine_rela (struct link_map *map,
- const Elf32_Rela *reloc,
- Elf32_Addr sym_loadaddr, const Elf32_Sym *sym)
+ const Elf32_Rela *reloc, const Elf32_Sym *sym,
+ Elf32_Addr (*resolve) (const Elf32_Sym **ref,
+ Elf32_Addr reloc_addr,
+ int noplt))
{
Elf32_Addr *const reloc_addr = (void *) (map->l_addr + reloc->r_offset);
- const Elf32_Addr sym_value = sym ? sym_loadaddr + sym->st_value : 0;
+ Elf32_Addr loadbase;
switch (ELF32_R_TYPE (reloc->r_info))
{
case R_68K_COPY:
- memcpy (reloc_addr, (void *) sym_value, sym->st_size);
+ loadbase = (*resolve) (&sym, (Elf32_Addr) reloc_addr, 0);
+ memcpy (reloc_addr, (void *) (loadbase + sym->st_value), sym->st_size);
break;
case R_68K_GLOB_DAT:
+ loadbase = (resolve ? (*resolve) (&sym, (Elf32_Addr) reloc_addr, 0) :
+ /* RESOLVE is null during bootstrap relocation. */
+ map->l_addr);
+ *reloc_addr = sym ? (loadbase + sym->st_value) : 0;
+ break;
case R_68K_JMP_SLOT:
- *reloc_addr = sym_value;
+ loadbase = (resolve ? (*resolve) (&sym, (Elf32_Addr) reloc_addr, 1) :
+ /* RESOLVE is null during bootstrap relocation. */
+ map->l_addr);
+ *reloc_addr = sym ? (loadbase + sym->st_value) : 0;
break;
case R_68K_8:
- *(char *) reloc_addr = sym_value + reloc->r_addend;
+ loadbase = (*resolve) (&sym, (Elf32_Addr) reloc_addr, 0);
+ *(char *) reloc_addr = ((sym ? (loadbase + sym->st_value) : 0)
+ + reloc->r_addend);
break;
case R_68K_16:
- *(short *) reloc_addr = sym_value + reloc->r_addend;
+ loadbase = (*resolve) (&sym, (Elf32_Addr) reloc_addr, 0);
+ *(short *) reloc_addr = ((sym ? (loadbase + sym->st_value) : 0)
+ + reloc->r_addend);
break;
case R_68K_32:
- *reloc_addr = sym_value + reloc->r_addend;
+ loadbase = (resolve ? (*resolve) (&sym, (Elf32_Addr) reloc_addr, 0) :
+ /* RESOLVE is null during bootstrap relocation. */
+ map->l_addr);
+ *reloc_addr = ((sym ? (loadbase + sym->st_value) : 0)
+ + reloc->r_addend);
break;
case R_68K_RELATIVE:
*reloc_addr = map->l_addr + reloc->r_addend;
break;
case R_68K_PC8:
- *(char *) reloc_addr = (sym_value + reloc->r_addend
+ loadbase = (*resolve) (&sym, (Elf32_Addr) reloc_addr, 0);
+ *(char *) reloc_addr = ((sym ? (loadbase + sym->st_value) : 0)
+ + reloc->r_addend
- (Elf32_Addr) reloc_addr);
break;
case R_68K_PC16:
- *(short *) reloc_addr = (sym_value + reloc->r_addend
+ loadbase = (*resolve) (&sym, (Elf32_Addr) reloc_addr, 0);
+ *(short *) reloc_addr = ((sym ? (loadbase + sym->st_value) : 0)
+ + reloc->r_addend
- (Elf32_Addr) reloc_addr);
break;
case R_68K_PC32:
- *reloc_addr = sym_value + reloc->r_addend - (Elf32_Addr) reloc_addr;
+ loadbase = (*resolve) (&sym, (Elf32_Addr) reloc_addr, 0);
+ *reloc_addr = ((sym ? (loadbase + sym->st_value) : 0)
+ + reloc->r_addend
+ - (Elf32_Addr) reloc_addr);
break;
case R_68K_NONE: /* Alright, Wilbur. */
break;
}
}
+/* Nonzero iff TYPE describes relocation of a PLT entry, so
+ PLT entries should not be allowed to define the value. */
+#define elf_machine_pltrel_p(type) ((type) == R_68K_JMP_SLOT)
+
/* The m68k never uses Elf32_Rel relocations. */
#define ELF_MACHINE_NO_REL 1
.globl _dl_runtime_resolve
.type _dl_runtime_resolve, @function
_dl_runtime_resolve:
- | Save %a0 (struct return address).
+ | Save %a0 (struct return address) and %a1.
move.l %a0, -(%sp)
+ move.l %a1, -(%sp)
| Call the real address resolver.
- bsr.l fixup
- | Restore register %a0.
+ jbsr fixup
+ | Restore register %a0 and %a1.
+ move.l (%sp)+, %a1
move.l (%sp)+, %a0
| Pop parameters
addq.l #8, %sp
jmp (%d0)
.size _dl_runtime_resolve, . - _dl_runtime_resolve
");
-#define ELF_MACHINE_RUNTIME_FIXUP_ARGS long int save_a0
+#define ELF_MACHINE_RUNTIME_FIXUP_ARGS long int save_a0, long int save_a1
+/* The PLT uses Elf32_Rela relocs. */
+#define elf_machine_relplt elf_machine_rela
}
.globl _start
.globl _dl_start_user
_start:
+ move.l %sp, -(%sp)
jbsr _dl_start
+ addq.l #4, %sp
_dl_start_user:
| Save the user entry point address in %a4.
move.l %d0, %a4
lea (%sp, %d0*4), %sp
| Push back the modified argument count.
move.l %d1, -(%sp)
+0: | Push _dl_default_scope[2] as argument in _dl_init_next call below.
+ move.l ([_dl_default_scope@GOT, %a5], 8), %d2
+0: move.l %d2, -(%sp)
| Call _dl_init_next to return the address of an initializer
| function to run.
-0: bsr.l _dl_init_next@PLTPC
+ bsr.l _dl_init_next@PLTPC
+ add.l #4, %sp | Pop argument.
| Check for zero return, when out of initializers.
tst.l %d0
jeq 1f
| Call the shared object initializer function.
- | NOTE: We depend only on the registers (%a4 and %a5)
+ | NOTE: We depend only on the registers (%d2, %a4 and %a5)
| and the return address pushed by this call;
| the initializer is called with the stack just
| as it appears on entry, and it is free to move