From: kurt Date: Mon, 22 Dec 2014 21:58:25 +0000 (+0000) Subject: Self-relocation code for i386. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=f67a8cac1a8347a62f974e58db7714ab9015c575;p=openbsd Self-relocation code for i386. --- diff --git a/lib/csu/i386/md_init.h b/lib/csu/i386/md_init.h index 584af51599d..11a84c367f1 100644 --- a/lib/csu/i386/md_init.h +++ b/lib/csu/i386/md_init.h @@ -1,4 +1,4 @@ -/* $OpenBSD: md_init.h,v 1.4 2013/12/03 06:21:41 guenther Exp $ */ +/* $OpenBSD: md_init.h,v 1.5 2014/12/22 21:58:25 kurt Exp $ */ /*- * Copyright (c) 2001 Ross Harvey @@ -84,3 +84,52 @@ " xorl %ebp,%ebp # mark deepest stack frame\n" \ " call ___start \n" \ " .previous") + +#define MD_RCRT0_START \ + __asm( \ + ".text \n" \ + " .align 4 \n" \ + " .globl __start \n" \ + " .globl _start \n" \ + "_start: \n" \ + "__start: \n" \ + " movl %esp,%eax # save SP for dl_boot_bind \n" \ + " subl $16*4,%esp # allocate dl_data \n" \ + " pushl $0 # push 0 for dynamicp (unused on i386) \n" \ + " movl %esp,%ebx \n" \ + " pushl %ebx # push dl_data for dl_boot_bind \n" \ + " \n" \ + " mov %eax, %esi # save stack for ___start \n" \ + " pushl %eax # push saved SP for dl_boot_bind \n" \ + " \n" \ + " call _dl_boot_bind@PLT # _dl_boot_bind(sp,dl_data,0) \n" \ + " addl $3*4,%esp # pop args \n" \ + " \n" \ + " movl %esi,%ebp \n" \ + " andl $~15,%esp # align stack\n" \ + " pushl $0 # cleanup\n" \ + " movl 0(%ebp),%eax # argc \n" \ + " leal 8(%ebp,%eax,4),%ecx #envp \n" \ + " leal 4(%ebp),%edx # argv \n" \ + " pushl %ecx \n" \ + " pushl %edx \n" \ + " pushl %eax \n" \ + " xorl %ebp,%ebp # mark deepest stack frame\n" \ + " call ___start # ___start(argc,argv,envp,0) \n" \ + " \n" \ + ".text \n" \ + " .align 4 \n" \ + " .globl _dl_printf \n" \ + " .type _dl_printf,@function \n" \ + "_dl_printf: \n" \ + " ret \n" \ + " \n" \ + ".text \n" \ + " .align 4 \n" \ + " .globl _dl_exit \n" \ + " .type _dl_exit,@function \n" \ + "_dl_exit: \n" \ + " mov $1, %eax \n" \ + " int $0x80 \n" \ + " ret \n" \ + " .previous") diff --git a/libexec/ld.so/i386/archdep.h b/libexec/ld.so/i386/archdep.h index 57badd1c871..bfa203fee87 100644 --- a/libexec/ld.so/i386/archdep.h +++ b/libexec/ld.so/i386/archdep.h @@ -1,4 +1,4 @@ -/* $OpenBSD: archdep.h,v 1.11 2010/01/02 12:16:35 kettenis Exp $ */ +/* $OpenBSD: archdep.h,v 1.12 2014/12/22 21:58:25 kurt Exp $ */ /* * Copyright (c) 1998 Per Fogelstrom, Opsycon AB @@ -67,6 +67,8 @@ RELOC_REL(Elf32_Rel *r, const Elf32_Sym *s, Elf32_Addr *p, unsigned long v) *p += v; } else if (ELF32_R_TYPE(r->r_info) == RELOC_GLOB_DAT) { *p += v + s->st_value; + } else if (ELF32_R_TYPE(r->r_info) == RELOC_32) { + *p += v + s->st_value; } else { _dl_printf("unknown bootstrap relocation\n"); _dl_exit(6); @@ -83,6 +85,7 @@ RELOC_RELA(Elf32_Rela *r, const Elf32_Sym *s, Elf32_Addr *p, unsigned long v, *p = v + r->r_addend; } else if (ELF32_R_TYPE(r->r_info) == RELOC_GLOB_DAT) { *p = v + s->st_value + r->r_addend; + } else if (ELF32_R_TYPE(r->r_info) == RELOC_NONE) { } else { _dl_printf("unknown bootstrap relocation\n"); _dl_exit(6);