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