]> Zhao Yanbai Git Server - minix.git/commitdiff
csu/build support for ELF
authorArun Thomas <arun@minix3.org>
Fri, 10 Dec 2010 22:20:12 +0000 (22:20 +0000)
committerArun Thomas <arun@minix3.org>
Fri, 10 Dec 2010 22:20:12 +0000 (22:20 +0000)
15 files changed:
Makefile
boot/Makefile
lib/Makefile
lib/csu/Makefile
lib/csu/i386-aout/Makefile [new file with mode: 0644]
lib/csu/i386-aout/crtso.S [moved from lib/csu/i386/crtso.S with 100% similarity]
lib/csu/i386-elf/Makefile [new file with mode: 0644]
lib/csu/i386-elf/crt1_c.c [new file with mode: 0644]
lib/csu/i386-elf/crt1_s.S [new file with mode: 0644]
lib/csu/i386-elf/crti.S [new file with mode: 0644]
lib/csu/i386-elf/crtn.S [new file with mode: 0644]
lib/elf_build.sh [new file with mode: 0755]
lib/libc/arch/i386/rts/brksize.S
share/mk/bsd.own.mk
share/mk/sys.mk

index b9856cb581647cf7ee8b00d94ec36cc2dbdf9f6c..ab4b1e01ab3b854dc13ba64921b7781cffbb6b8a 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,7 @@
 # Master Makefile to compile everything in /usr/src except the system.
 
+.include <bsd.own.mk>
+
 MAKE=make
 
 usage:
@@ -33,7 +35,11 @@ usage:
 .if ${COMPILER_TYPE} == "ack"
 world: mkfiles includes depend libraries install etcforce
 .elif ${COMPILER_TYPE} == "gnu"
+.if ${OBJECT_FMT} == "a.out"
 world: mkfiles includes depend gnu-libraries install etcforce
+.elif ${OBJECT_FMT} == "ELF"
+world: mkfiles elf-includes depend elf-libraries install etcforce
+.endif
 .endif
 
 mkfiles:
@@ -60,43 +66,52 @@ gnu-libraries: gnu-includes
 clang-libraries: includes
        $(MAKE) -C lib build_clang
 
+MKHEADERS443_ELF=/usr/gnu_cross/libexec/gcc/i386-pc-minix3/4.4.3/install-tools/mkheaders
+elf-includes: includes
+       cp -r /usr/include/* /usr/gnu_cross/i386-pc-minix3/sys-include
+       SHELL=/bin/sh; if [ -f $(MKHEADERS443_ELF) ] ; then sh -e $(MKHEADERS443_ELF) ; fi
+
+elf-libraries: elf-includes
+       $(MAKE) -C lib build_elf
+
 commands: includes libraries
        $(MAKE) -C commands all
 
-depend::
+depend:
        $(MAKE) -C boot depend
        $(MAKE) -C commands depend
        $(MAKE) -C kernel depend
        $(MAKE) -C servers depend
        $(MAKE) -C drivers depend
 
-etcfiles::
+etcfiles:
        $(MAKE) -C etc install
 
-etcforce::
+etcforce:
        $(MAKE) -C etc installforce
 
-all::
+all:
        $(MAKE) -C boot all
        $(MAKE) -C commands all
        $(MAKE) -C tools all
 
-install::
+install:
        $(MAKE) -C boot install
        $(MAKE) -C man install makedb
        $(MAKE) -C commands install
        $(MAKE) -C share install
        $(MAKE) -C tools install
 
-clean::
+clean:
        $(MAKE) -C boot clean
        $(MAKE) -C commands clean
        $(MAKE) -C tools clean
        $(MAKE) -C lib clean_gnu
        $(MAKE) -C lib clean_ack
+       $(MAKE) -C lib clean_elf
        $(MAKE) -C test clean
 
-cleandepend::
+cleandepend:
        $(MAKE) -C boot cleandepend
        $(MAKE) -C commands cleandepend
        $(MAKE) -C tools cleandepend
index b2b9292edb79b5aea910b97b88b736a2d72e5980..07571cbe3b6c16bae2494e60fd4f2e5d7e94b9b7 100644 (file)
@@ -1,7 +1,7 @@
 # Makefile for the boot monitor package.
 
 # XXX: Can only be built with ACK currently
-CC:=${CC:C/^gcc/cc/}
+CC:=${CC:C/^.*gcc/cc/}
 COMPILER_TYPE:=ack
 
 PROGS= bootblock cdbootblock boot masterboot \
index 7fc948460608bb61df95372cbe65c0f00efe7aed..80e1baa05c5fcfc7582d63c8ece03bb0a85136bb 100644 (file)
@@ -1,6 +1,6 @@
 .include <bsd.own.mk>
 
-SUBDIR= csu libc libcurses libdriver libnetdriver libend libedit libm libsys \
+SUBDIR= csu libc libcurses libdriver libnetdriver libedit libm libsys \
        libtimers libutil libbz2 libl libhgfs libz libfetch libarchive \
        libvtreefs libaudiodriver libmthread libexec
 
@@ -8,6 +8,10 @@ SUBDIR= csu libc libcurses libdriver libnetdriver libend libedit libm libsys \
 SUBDIR+= ack/libd ack/libe ack/libfp ack/liby
 .endif
 
+.if ${OBJECT_FMT} == "a.out"
+SUBDIR+= libend
+.endif
+
 .include <bsd.subdir.mk>
 
 build_ack:
@@ -19,8 +23,14 @@ build_gnu:
 build_clang:
        sh clang_build.sh obj depend all install
 
+build_elf:
+       sh elf_build.sh obj depend all install
+
 clean_ack:
        sh ack_build.sh clean
 
 clean_gnu:
        sh gnu_build.sh clean
+
+clean_elf:
+       sh elf_build.sh clean
index 78c737fb37530564b26283564ba84e4b92d4b470..a34bd119d8b9ed97bb32cbedfdc0627c826797b3 100644 (file)
@@ -1,14 +1,9 @@
 .include <bsd.own.mk>
 
-.PATH: ${.CURDIR}/${ARCH}
+.if ${OBJECT_FMT} == "a.out"
+SUBDIR=${ARCH}-aout
+.elif ${OBJECT_FMT} == "ELF"
+SUBDIR=${ARCH}-elf
+.endif
 
-SRCS=  crtso.S
-OBJS=  crtso.o
-
-realall: ${OBJS}
-
-FILES=${OBJS}
-FILESDIR=${LIBDIR}
-CLEANFILES=${OBJS}
-
-.include <bsd.prog.mk>
+.include <bsd.subdir.mk>
diff --git a/lib/csu/i386-aout/Makefile b/lib/csu/i386-aout/Makefile
new file mode 100644 (file)
index 0000000..558fd66
--- /dev/null
@@ -0,0 +1,12 @@
+.include <bsd.own.mk>
+
+SRCS=  crtso.S
+OBJS=  crtso.o
+
+realall: ${OBJS}
+
+FILES=${OBJS}
+FILESDIR=${LIBDIR}
+CLEANFILES=${OBJS}
+
+.include <bsd.prog.mk>
diff --git a/lib/csu/i386-elf/Makefile b/lib/csu/i386-elf/Makefile
new file mode 100644 (file)
index 0000000..54a645d
--- /dev/null
@@ -0,0 +1,29 @@
+.include <bsd.own.mk>
+
+SRCS=          crti.S crtn.S
+OBJS=          ${SRCS:N*.h:R:S/$/.o/g} gcrt1.o crt1.o Scrt1.o
+
+realall: ${OBJS}
+
+FILES=${OBJS}
+FILESDIR=${LIBDIR}
+CLEANFILES=${OBJS} crt1_c.o crt1_s.o gcrt1_c.o Scrt1_c.o
+
+gcrt1_c.o: crt1_c.c
+       ${CC} ${CFLAGS} -DGCRT -c -o gcrt1_c.o ${.CURDIR}/crt1_c.c
+
+gcrt1.o: gcrt1_c.o crt1_s.o
+       ${LD} ${LDFLAGS} -o gcrt1.o -r crt1_s.o gcrt1_c.o
+
+crt1.o:        crt1_c.o crt1_s.o
+       ${LD} ${LDFLAGS} -o crt1.o -r crt1_s.o crt1_c.o
+       ${OBJCOPY} --localize-symbol _start1 crt1.o
+
+Scrt1_c.o:     crt1_c.c
+       ${CC} ${CFLAGS} -fPIC -DPIC -c -o Scrt1_c.o ${.CURDIR}/crt1_c.c
+
+Scrt1.o: Scrt1_c.o crt1_s.o
+       ${LD} ${LDFLAGS} -o Scrt1.o -r crt1_s.o Scrt1_c.o
+       ${OBJCOPY} --localize-symbol _start1 Scrt1.o
+
+.include <bsd.prog.mk>
diff --git a/lib/csu/i386-elf/crt1_c.c b/lib/csu/i386-elf/crt1_c.c
new file mode 100644 (file)
index 0000000..25dc5ac
--- /dev/null
@@ -0,0 +1,94 @@
+/* LINTLIBRARY */
+/*-
+ * Copyright 1996-1998 John D. Polstra.
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef lint
+#ifndef __GNUC__
+#error "GCC is needed to compile this file"
+#endif
+#endif /* lint */
+
+#include <stdlib.h>
+
+extern int _DYNAMIC;
+#pragma weak _DYNAMIC
+
+typedef void (*fptr)(void);
+
+extern void _fini(void);
+extern void _init(void);
+extern int main(int, char **, char **);
+extern void _start(char *, ...);
+
+#ifdef GCRT
+extern void _mcleanup(void);
+extern void monstartup(void *, void *);
+extern int eprol;
+extern int etext;
+#endif
+
+char **environ;
+const char *__progname = "";
+
+__dead void _start1(fptr, int, char *[]);
+
+/* The entry function, C part. */
+__dead void
+_start1(fptr cleanup, int argc, char *argv[])
+{
+       char **env;
+       const char *s;
+
+       env = argv + argc + 1;
+       environ = env;
+       if (argc > 0 && argv[0] != NULL) {
+               __progname = argv[0];
+               for (s = __progname; *s != '\0'; s++)
+                       if (*s == '/')
+                               __progname = s + 1;
+       }
+
+#if 0
+       if (&_DYNAMIC != NULL)
+               atexit(cleanup);
+       else
+               _init_tls();
+#endif
+
+#ifdef GCRT
+       atexit(_mcleanup);
+#endif
+       atexit(_fini);
+#ifdef GCRT
+       monstartup(&eprol, &etext);
+__asm__("eprol:");
+#endif
+       _init();
+       exit( main(argc, argv, env) );
+}
+
+__asm(".hidden _start1");
diff --git a/lib/csu/i386-elf/crt1_s.S b/lib/csu/i386-elf/crt1_s.S
new file mode 100644 (file)
index 0000000..e101330
--- /dev/null
@@ -0,0 +1,51 @@
+/*-
+ * Copyright 2009 Konstantin Belousov.
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ *
+ * $FreeBSD$
+ */
+
+
+       .text
+       .align  4
+       .globl  _start
+       .type   _start, @function
+_start:
+       .cfi_startproc
+       xorl    %ebp,%ebp
+       pushl   %ebp
+       .cfi_def_cfa_offset 4
+       movl    %esp,%ebp
+       .cfi_offset %ebp,-8
+       .cfi_def_cfa_register %ebp
+       andl    $0xfffffff0,%esp # align stack
+       leal    8(%ebp),%eax
+       pushl   %eax            # argv
+       pushl   4(%ebp)         # argc
+       pushl   %edx            # rtld cleanup
+       call    _start1
+       int3
+       .cfi_endproc
+       .size   _start, . - _start
+
+       .ident  "$MINIX$"
diff --git a/lib/csu/i386-elf/crti.S b/lib/csu/i386-elf/crti.S
new file mode 100644 (file)
index 0000000..f06517c
--- /dev/null
@@ -0,0 +1,41 @@
+/*-
+ * Copyright 1996, 1997, 1998, 2000 John D. Polstra.
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ */
+
+       .section .init,"ax",@progbits
+       .align  4
+       .globl  _init
+       .type   _init,@function
+_init:
+       sub     $12,%esp        /* re-align stack pointer */
+
+       .section .fini,"ax",@progbits
+       .align  4
+       .globl  _fini
+       .type   _fini,@function
+_fini:
+       sub     $12,%esp        /* re-align stack pointer */
+
+       .section .rodata
+.ascii "$MINIX$\0"
diff --git a/lib/csu/i386-elf/crtn.S b/lib/csu/i386-elf/crtn.S
new file mode 100644 (file)
index 0000000..ae07547
--- /dev/null
@@ -0,0 +1,35 @@
+/*-
+ * Copyright 1996, 1997, 1998, 2000 John D. Polstra.
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ */
+
+       .section .init,"ax",@progbits
+       add     $12,%esp
+       ret
+
+       .section .fini,"ax",@progbits
+       add     $12,%esp
+       ret
+
+       .section .rodata
+.ascii "$MINIX$\0"
diff --git a/lib/elf_build.sh b/lib/elf_build.sh
new file mode 100755 (executable)
index 0000000..2d4d5fe
--- /dev/null
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+export CC=i386-pc-minix3-gcc
+export COMPILER_TYPE=gnu
+export MAKEOBJDIR=obj-elf
+export PATH=$PATH:/usr/gnu_cross/bin
+
+make $@
index 43b3033b251932bf4ddc1aabf5204d2b675aa159..64ec062d1d9416b6e769fe1775109165a5605bf1 100644 (file)
@@ -1,5 +1,13 @@
+#if defined(__ELF__)
+.globl _end
+.globl _brksize
+
+.data
+_brksize: .long _end
+#else
 .globl __brksize
 .data
 .extern        endbss, __brksize
 __brksize:
 .long  endbss
+#endif
index f3c64e1bc4ffff040f87ef1a96d21a26ee1d241e..f8164681710aa94afbdcbf8e56401856c34b2029 100644 (file)
@@ -483,8 +483,6 @@ INFOMODE?=  ${NONBINMODE}
 #LIBDIR?=      /usr/lib
 .if ${COMPILER_TYPE} == "ack"
 LIBDIR?=       /usr/lib/i386
-.elif ${COMPILER_TYPE} == "gnu"
-LIBDIR?=       /usr/lib
 .endif
 
 LINTLIBDIR?=   /usr/libdata/lint
@@ -533,7 +531,18 @@ DEBUGMODE?=        ${NONBINMODE}
 # All platforms are ELF.
 #
 #OBJECT_FMT=   ELF
+.if !empty(CC:Mi386-pc-minix3-gcc)
+OBJECT_FMT=    ELF
+.else
 OBJECT_FMT=    a.out
+.endif
+.if ${COMPILER_TYPE} == "gnu"
+.if ${OBJECT_FMT} == "a.out"
+LIBDIR?=       /usr/lib
+.elif ${OBJECT_FMT} == "ELF"
+LIBDIR?=       /usr/gnu_cross/i386-pc-minix3/lib
+.endif
+.endif
 
 #
 # If this platform's toolchain is missing, we obviously cannot build it.
index f44905974f9e37b52c1e252d3130bc2f2c842c5e..1488fb2cb9d1135aa93aa2bccd9c5715da7fff98 100644 (file)
@@ -233,4 +233,9 @@ AR=ar
 .elif !empty(CC:Mclang)
 COMPILER_TYPE=gnu
 AR=ar
+.elif !empty(CC:Mi386-pc-minix3-gcc)
+COMPILER_TYPE=gnu
+AR=i386-pc-minix3-ar
+LD=i386-pc-minix3-ld
+OBJCOPY=i386-pc-minix3-objcopy
 .endif