self-relocating crt0 bits for sh, and enable static pie by default. With some
authormiod <miod@openbsd.org>
Tue, 30 Dec 2014 19:26:38 +0000 (19:26 +0000)
committermiod <miod@openbsd.org>
Tue, 30 Dec 2014 19:26:38 +0000 (19:26 +0000)
archdep.h help from kettenis@

gnu/gcc/gcc/config/sh/openbsd.h
gnu/usr.bin/binutils/ld/emulparams/shelf_obsd.sh
lib/csu/sh/md_init.h
libexec/ld.so/sh/archdep.h
share/mk/bsd.own.mk

index 20521a7..cb665a2 100644 (file)
@@ -90,7 +90,8 @@ Boston, MA 02110-1301, USA.  */
 /* As an elf system, we need crtbegin/crtend stuff.  */
 #undef STARTFILE_SPEC
 #define STARTFILE_SPEC "\
-       %{!shared: %{pg:gcrt0%O%s} %{!pg:%{p:gcrt0%O%s} %{!p:crt0%O%s}} \
+       %{!shared: %{pg:gcrt0%O%s} %{!pg:%{p:gcrt0%O%s} \
+       %{!p:%{!static:crt0%O%s} %{static:%{pie:rcrt0%O%s} %{!pie:crt0%O%s}}}} \
        crtbegin%O%s} %{shared:crtbeginS%O%s}"
 #undef ENDFILE_SPEC
 #define ENDFILE_SPEC "%{!shared:crtend%O%s} %{shared:crtendS%O%s}"
index 03883ef..2fa0f71 100644 (file)
@@ -10,7 +10,7 @@ MAXPAGESIZE=0x10000
 
 DATA_START_SYMBOLS='__data_start = . ;';
 
-ENTRY=_start
+ENTRY=__start
 
 unset EMBEDDED
 unset OTHER_SECTIONS
index 6fb408d..7a1b5d9 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: md_init.h,v 1.3 2014/04/18 15:09:52 guenther Exp $    */
+/*     $OpenBSD: md_init.h,v 1.4 2014/12/30 19:26:38 miod Exp $        */
 /*     $NetBSD: dot_init.h,v 1.3 2005/12/24 22:02:10 perry Exp $       */
 
 /*-
@@ -68,15 +68,12 @@ __asm(".section " #section "\n"             \
 "2:  .previous");
 
 
-/* no ASM stub for __start; the C routine can be called directly */
-#define        MD_START        __start
-
 #if defined(__SH4__) && !defined(__SH4_NOFPU__)
 #include <machine/fpu.h>
 
-#define        MD_CRT0_START                           \
+#define        MD_FPU_START                            \
        void __set_fpscr(unsigned int);         \
-       unsigned int __fpscr_values[2]
+       unsigned int __fpscr_values[2];
 
 #define        MD_START_SETUP                          \
        __set_fpscr(0);                         \
@@ -84,5 +81,69 @@ __asm(".section " #section "\n"              \
        __fpscr_values[1] |= FPSCR_DN;          \
        __asm volatile ("lds %0, fpscr"         \
            : : "r" (__fpscr_values[1]));
+#else
+#define        MD_FPU_START
 #endif /* defined(__SH4__) && !defined(__SH4_NOFPU__) */
 
+#define        MD_CRT0_START                                                   \
+       MD_FPU_START                                                    \
+       __asm (".globl __start; __start = ___start")
+
+#define        MD_RCRT0_START                                                  \
+       MD_FPU_START                                                    \
+       __asm (                                                         \
+       ".text                                                          \n" \
+       "       .align  2                                               \n" \
+       "       .globl  __start                                         \n" \
+       "       .type   __start,@function                               \n" \
+       "__start:                                                       \n" \
+       "       mov     r15, r12                                        \n" \
+       "       mov     r15, r4                                         \n" \
+       "       add     #-72, r15                                       \n" \
+       "       mov     r15, r5                                         \n" \
+       "       bsr     1f                                              \n" \
+       "        nop                                                    \n" \
+       "1:                                                             \n" \
+       ".L_offbase:                                                    \n" \
+       "       sts     pr, r0                                          \n" \
+       "       mov.l   .L_dynamic, r6                                  \n" \
+       "       add     r0, r6                                          \n" \
+       "       mov.l   .L_boot_bind, r0                                \n" \
+       "       bsrf    r0                                              \n" \
+       "        nop                                                    \n" \
+       ".L_call_boot_bind:                                             \n" \
+       "       mov     r12, r15                                        \n" \
+       "       mov.l   @r15, r4        /* argc */                      \n" \
+       "       mov     r15, r5                                         \n" \
+       "       add     #4, r5          /* argv */                      \n" \
+       "       mov     r4, r6                                          \n" \
+       "       add     #1, r6                                          \n" \
+       "       shll2   r6                                              \n" \
+       "       add     r5, r6          /* envp */                      \n" \
+       "       bra     ___start                                        \n" \
+       "        mov    #0, r7          /* cleanup */                   \n" \
+       "       .align  2                                               \n" \
+       ".L_boot_bind:                                                  \n" \
+       "       .long   _dl_boot_bind - .L_call_boot_bind               \n" \
+       ".L_datasize:                                                   \n" \
+       "       .long   4 + 4 + (16 * 4)                                \n" \
+       ".L_dynamic:                                                    \n" \
+       "       .long   _DYNAMIC - .L_offbase                           \n" \
+                                                                       \
+       "       .align  2                                               \n" \
+       "       .globl  _dl_printf                                      \n" \
+       "       .type   _dl_printf,@function                            \n" \
+       "_dl_printf:                                                    \n" \
+       "       rts                                                     \n" \
+       "        nop                                                    \n" \
+                                                                       \
+       "       .align  2                                               \n" \
+       "       .globl  _dl_exit                                        \n" \
+       "       .type   _dl_exit,@function                              \n" \
+       "_dl_exit:                                                      \n" \
+       "       mov     #1, r0                                          \n" \
+       "       .word   0xc380  /* trapa #0x80 */                       \n" \
+       ".previous")
+
+/* no ASM stub for __start; the C routine can be called directly */
+#define        MD_START        ___start
index 8da20ac..00f8aaf 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: archdep.h,v 1.3 2014/07/05 12:22:41 miod Exp $ */
+/*     $OpenBSD: archdep.h,v 1.4 2014/12/30 19:26:38 miod Exp $ */
 
 /*
  * Copyright (c) 1998 Per Fogelstrom, Opsycon AB
@@ -74,6 +74,8 @@ RELOC_RELA(Elf32_Rela *r, const Elf32_Sym *s, Elf32_Addr *p, unsigned long v,
 {
        if (ELF_R_TYPE(r->r_info) == R_SH_RELATIVE) {
                *p = v + r->r_addend;
+       } else if (ELF_R_TYPE(r->r_info) == R_SH_DIR32) {
+               *p = s->st_value + v + r->r_addend;
        } else {
                /* XXX - printf might not work here, but we give it a shot. */
                _dl_printf("Unknown bootstrap relocation.\n");
index 04bac25..fb78b9e 100644 (file)
@@ -1,4 +1,4 @@
-#      $OpenBSD: bsd.own.mk,v 1.156 2014/12/28 05:17:21 deraadt Exp $
+#      $OpenBSD: bsd.own.mk,v 1.157 2014/12/30 19:26:38 miod Exp $
 #      $NetBSD: bsd.own.mk,v 1.24 1996/04/13 02:08:09 thorpej Exp $
 
 # Host-specific overrides
@@ -25,7 +25,7 @@ BINUTILS217_ARCH=hppa64 ia64
 # m88k unknown
 # hppa64 unknown
 PIE_ARCH=alpha amd64 hppa i386 mips64 mips64el powerpc sh sparc64
-STATICPIE_ARCH=alpha amd64 hppa i386 powerpc sparc64
+STATICPIE_ARCH=alpha amd64 hppa i386 powerpc sh sparc64
 
 .for _arch in ${MACHINE_ARCH}
 .if !empty(GCC3_ARCH:M${_arch})