Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/csu Switch i386 and x86_64 to the new CRT layout. The cr...



details:   https://anonhg.NetBSD.org/src/rev/39370e8c677a
branches:  trunk
changeset: 756910:39370e8c677a
user:      joerg <joerg%NetBSD.org@localhost>
date:      Sat Aug 07 18:01:32 2010 +0000

description:
Switch i386 and x86_64 to the new CRT layout. The crt0.c body is shared
between all platforms and a small assembler stub in crt0.S is used for
setting up the proper stack and whatever else MD needs.

Extract crti.S and crtn. from the old dot_init.h files. Prepare other
platforms that use the 6-argument form of __(_)start for this.

Rewrite the crtbegin and crtend modules in assembler to make them
compiler independent. Document the interface in README.

diffstat:

 lib/csu/Makefile                 |   31 ++++--
 lib/csu/README                   |   63 ++++++++++++++
 lib/csu/arch/arm/Makefile.inc    |    5 +
 lib/csu/arch/arm/crt0.S          |   56 ++++++++++++
 lib/csu/arch/arm/crti.S          |   56 ++++++++++++
 lib/csu/arch/arm/crtn.S          |   44 +++++++++
 lib/csu/arch/i386/Makefile.inc   |    5 +
 lib/csu/arch/i386/crt0.S         |   53 +++++++++++
 lib/csu/arch/i386/crtbegin.S     |  174 +++++++++++++++++++++++++++++++++++++++
 lib/csu/arch/i386/crtend.S       |   52 +++++++++++
 lib/csu/arch/i386/crti.S         |   54 ++++++++++++
 lib/csu/arch/i386/crtn.S         |   46 ++++++++++
 lib/csu/arch/m68k/Makefile.inc   |    5 +
 lib/csu/arch/m68k/crt0.S         |   52 +++++++++++
 lib/csu/arch/m68k/crti.S         |   50 +++++++++++
 lib/csu/arch/m68k/crtn.S         |   44 +++++++++
 lib/csu/arch/sh3/Makefile.inc    |    5 +
 lib/csu/arch/sh3/crt0.S          |   47 ++++++++++
 lib/csu/arch/sh3/crti.S          |   56 ++++++++++++
 lib/csu/arch/sh3/crtn.S          |   50 +++++++++++
 lib/csu/arch/sparc/Makefile.inc  |    5 +
 lib/csu/arch/sparc/crt0.S        |   56 ++++++++++++
 lib/csu/arch/sparc/crti.S        |   78 +++++++++++++++++
 lib/csu/arch/sparc/crtn.S        |   74 ++++++++++++++++
 lib/csu/arch/vax/Makefile.inc    |    5 +
 lib/csu/arch/vax/crt0.S          |   53 +++++++++++
 lib/csu/arch/vax/crti.S          |   52 +++++++++++
 lib/csu/arch/vax/crtn.S          |   44 +++++++++
 lib/csu/arch/x86_64/Makefile.inc |    3 +
 lib/csu/arch/x86_64/crt0.S       |   52 +++++++++++
 lib/csu/arch/x86_64/crtbegin.S   |  157 +++++++++++++++++++++++++++++++++++
 lib/csu/arch/x86_64/crtend.S     |   52 +++++++++++
 lib/csu/arch/x86_64/crti.S       |   52 +++++++++++
 lib/csu/arch/x86_64/crtn.S       |   46 ++++++++++
 lib/csu/common/Makefile.inc      |   86 +++++++++++++++++++
 lib/csu/common/crt0-common.c     |  124 +++++++++++++++++++++++++++
 lib/csu/common/sysident.S        |   77 +++++++++++++++++
 lib/csu/common/sysident_assym.cf |   12 ++
 lib/csu/i386_elf/Makefile        |    6 -
 lib/csu/i386_elf/crt0.c          |  105 -----------------------
 lib/csu/i386_elf/dot_init.h      |   65 --------------
 lib/csu/x86_64/Makefile          |    6 -
 lib/csu/x86_64/crt0.c            |  104 -----------------------
 lib/csu/x86_64/dot_init.h        |   64 --------------
 44 files changed, 1965 insertions(+), 361 deletions(-)

diffs (truncated from 2513 to 300 lines):

diff -r f43bc53af94c -r 39370e8c677a lib/csu/Makefile
--- a/lib/csu/Makefile  Sat Aug 07 17:12:55 2010 +0000
+++ b/lib/csu/Makefile  Sat Aug 07 18:01:32 2010 +0000
@@ -1,22 +1,31 @@
-#      $NetBSD: Makefile,v 1.26 2010/07/05 21:27:55 mrg Exp $
+#      $NetBSD: Makefile,v 1.27 2010/08/07 18:01:32 joerg Exp $
 
 .include <bsd.own.mk>
 
-.if exists(${CSU_MACHINE_ARCH}_elf)
+CSU_MACHINE_ARCH?=     ${MACHINE_ARCH}
+
+.if ${CSU_MACHINE_ARCH} == "i386" || ${CSU_MACHINE_ARCH} == "x86_64"
+ARCHDIR:=      ${.PARSEDIR}/arch/${CSU_MACHINE_ARCH}
+.PATH: ${ARCHDIR}
+.  include "${ARCHDIR}/Makefile.inc"
+
+.  include "${.PARSEDIR}/common/Makefile.inc"
+.else
+
+.  if exists(${CSU_MACHINE_ARCH}_elf/Makefile)
 SUBDIR=        ${CSU_MACHINE_ARCH}_elf
-.elif exists(${MACHINE_ARCH}_elf)
-SUBDIR=        ${MACHINE_ARCH}_elf
-.elif exists(${MACHINE_CPU}_elf)
+.  elif exists(${CSU_MACHINE_ARCH}/Makefile)
+SUBDIR=        ${CSU_MACHINE_ARCH}
+.  elif exists(${MACHINE_CPU}_elf/Makefile)
 SUBDIR=        ${MACHINE_CPU}_elf
-.elif exists(${MACHINE_ARCH})
-SUBDIR=        ${MACHINE_ARCH}
-.elif exists(${MACHINE_CPU})
+.  elif exists(${MACHINE_CPU}/Makefile)
 SUBDIR=        ${MACHINE_CPU}
-.else
+.  else
 .BEGIN:
        @echo no SUBDIR for ${MACHINE_ARCH}_elf, ${MACHINE_ARCH} nor \
            ${MACHINE_CPU}
        @false
-.endif
+.  endif
 
-.include <bsd.subdir.mk>
+.  include <bsd.subdir.mk>
+.endif
diff -r f43bc53af94c -r 39370e8c677a lib/csu/README
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/csu/README    Sat Aug 07 18:01:32 2010 +0000
@@ -0,0 +1,63 @@
+Overview of the common runtime support
+
+The common runtime support contains two modules, crtbegin and crtend.
+crtbegin is linked before all other object files of the program or
+dynamic library, crtend after all other object files.  They frame the
+lists of constructors, destructors, Java types and exception handling frames.
+
+If done correctly, crtend contains no code and is therefore position
+independent.  crtendS.o is therefore just a link to crtend.o.
+
+crtbegin should be position-independent code.  crtbeginT.o doesn't have
+to be PIC as it is statically linked.  The overhead is generally not
+worth the trouble though.
+
+
+Section types:
+.ctor: writeable
+.dtor: writeable
+.eh_frame: read-only if platform allows mixing read-only and read-write
+sections.  This is supported by GNU ld.
+.jcr: writeable
+.init: executable
+.fini: executable
+
+
+Non-local symbols:
+
+Weak references:
+- _Jv_RegisterClasses,
+- __cxa_finalize (crtbeginS.o)
+- __deregister_frame_info
+- __register_frame_info
+
+Hidden:
+- __dso_handle: pointer to self for crtbeginS.o, NULL otherwise.
+- __CTOR_LIST_END__
+
+
+Initialisation (called from .init):
+
+1.  Check that the init code hasn't started already, otherwise bail out.
+2.  If __register_frame_info is NULL, skip to 4
+3.  Call __register_frame_info with start of .eh_frame as first argument
+    and a data object of at least 8 pointers as second argument.
+4:  If _Jv_RegisterClasses is NULL, skip to 6
+5:  Call _Jv_RegisterClasses with the first pointer of the .jcr section
+    as argument.
+6:  Iterate from the end of the .ctor section to the start.  Skip the
+    terminating NULL and stop when reaching the starting (void *)-1 element.
+    Call the pointers as void (*)(void) functions.
+
+
+Deinitialisation (called from .fini):
+
+1.  Check if the init code has already started, otherwise bail out.
+2.  If this is not crtbeginS.o or __cxa_finalize is NULL, skip to 4.
+3.  Call __cxa_finalize with a pointer into this Dynamic Shared Object (DSO)
+    as first argument.
+4.  Iterate from the start of the .dtor section to the send.  Skip the
+    initial (void *)-1 and stop when reaching the terminating NULL element.
+    Call the pointers as void (*)(void) functions.
+5.  If __deregister_frame_info is NULL, return.
+6.  Call __deregister_frame_info with the start of .eh_frame as the argument.
diff -r f43bc53af94c -r 39370e8c677a lib/csu/arch/arm/Makefile.inc
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/csu/arch/arm/Makefile.inc     Sat Aug 07 18:01:32 2010 +0000
@@ -0,0 +1,5 @@
+# $NetBSD: Makefile.inc,v 1.1 2010/08/07 18:01:33 joerg Exp $
+
+CPPFLAGS+=     -DELFSIZE=32
+
+
diff -r f43bc53af94c -r 39370e8c677a lib/csu/arch/arm/crt0.S
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/csu/arch/arm/crt0.S   Sat Aug 07 18:01:32 2010 +0000
@@ -0,0 +1,56 @@
+/*     $NetBSD: crt0.S,v 1.1 2010/08/07 18:01:33 joerg Exp $   */
+
+/*
+ * Copyright (C) 1997 Mark Brinicombe
+ * Copyright (C) 1995 Wolfgang Solfrank.
+ * Copyright (C) 1995 TooLs GmbH.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by TooLs GmbH.
+ * 4. The name of TooLs GmbH may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <machine/asm.h>
+
+RCSID("$NetBSD: crt0.S,v 1.1 2010/08/07 18:01:33 joerg Exp $")
+
+STRONG_ALIAS(_start,__start)
+
+_ENTRY(__start)
+       mov     r5, r2          /* cleanup */
+       mov     r4, r1          /* obj_main */
+       mov     r3, r0          /* ps_strings */
+       /* Get argc, argv, and envp from stack */
+       ldr     r0, [sp, #0x0000]
+       add     r1, sp, #0x0004
+       add     r2, r1, r0, lsl #2
+       add     r2, r2, #0x0004
+
+       /* Ensure the stack is properly aligned before calling C code. */
+       bic     sp, sp, #7
+       sub     sp, sp, #8
+       str     r5, [sp, #4]
+       str     r4, [sp, #0]
+
+       b       ___start
diff -r f43bc53af94c -r 39370e8c677a lib/csu/arch/arm/crti.S
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/csu/arch/arm/crti.S   Sat Aug 07 18:01:32 2010 +0000
@@ -0,0 +1,56 @@
+/* $NetBSD: crti.S,v 1.1 2010/08/07 18:01:33 joerg Exp $ */
+
+/*-
+ * Copyright (c) 2001 Ross Harvey
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the NetBSD
+ *     Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <machine/asm.h>
+
+RCSID("$NetBSD: crti.S,v 1.1 2010/08/07 18:01:33 joerg Exp $")
+
+#include "sysident.S"
+
+       .section ".init", "ax", @progbits
+       .align 0
+       .globl _init
+_init:
+       mov     ip, sp
+       stmfd   sp!, {fp, ip, lr, pc}
+       sub     fp, ip, #4
+
+       .section ".fini", "ax", @progbits
+       .align 0
+       .globl _fini
+_fini:
+       mov     ip, sp
+       stmfd   sp!, {fp, ip, lr, pc}
+       sub     fp, ip, #4
diff -r f43bc53af94c -r 39370e8c677a lib/csu/arch/arm/crtn.S
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/csu/arch/arm/crtn.S   Sat Aug 07 18:01:32 2010 +0000
@@ -0,0 +1,44 @@
+/* $NetBSD: crtn.S,v 1.1 2010/08/07 18:01:33 joerg Exp $ */
+
+/*-
+ * Copyright (c) 2001 Ross Harvey
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the NetBSD
+ *     Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <machine/asm.h>
+
+RCSID("$NetBSD: crtn.S,v 1.1 2010/08/07 18:01:33 joerg Exp $")
+
+       .section ".init", "ax", @progbits
+       ldmea   fp, {fp, sp, pc}
+
+       .section ".fini", "ax", @progbits
+       ldmea   fp, {fp, sp, pc}
diff -r f43bc53af94c -r 39370e8c677a lib/csu/arch/i386/Makefile.inc
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/csu/arch/i386/Makefile.inc    Sat Aug 07 18:01:32 2010 +0000
@@ -0,0 +1,5 @@
+# $NetBSD: Makefile.inc,v 1.1 2010/08/07 18:01:33 joerg Exp $
+
+CPPFLAGS+=     -DELFSIZE=32
+
+
diff -r f43bc53af94c -r 39370e8c677a lib/csu/arch/i386/crt0.S



Home | Main Index | Thread Index | Old Index