csu/build support for ELF

This commit is contained in:
Arun Thomas 2010-12-10 22:20:12 +00:00
parent a53d925844
commit d824b54d82
15 changed files with 334 additions and 22 deletions

View file

@ -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

View 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 \

View 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

View 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>

View file

@ -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>

29
lib/csu/i386-elf/Makefile Normal file
View file

@ -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>

94
lib/csu/i386-elf/crt1_c.c Normal file
View file

@ -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");

51
lib/csu/i386-elf/crt1_s.S Normal file
View file

@ -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$"

41
lib/csu/i386-elf/crti.S Normal file
View file

@ -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"

35
lib/csu/i386-elf/crtn.S Normal file
View file

@ -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"

8
lib/elf_build.sh Executable file
View file

@ -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 $@

View 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

View 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.

View 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