diff --git a/lib/csu/Makefile.inc b/lib/csu/Makefile.inc index ee60c3968b87..9c3352296651 100644 --- a/lib/csu/Makefile.inc +++ b/lib/csu/Makefile.inc @@ -1,85 +1,79 @@ # $FreeBSD$ NO_WMISSING_VARIABLE_DECLARATIONS= # Can't instrument these files since that breaks non-sanitized programs. MK_ASAN:= no MK_UBSAN:= no .include MK_SSP= no .if !defined(BUILDING_TESTS) OBJS+= Scrt1.o crt1.o gcrt1.o OBJS+= crtbegin.o crtbeginS.o crtbeginT.o OBJS+= crtend.o crtendS.o OBJS+= crti.o crtn.o CRT1OBJS+= crtbrand.o feature_note.o ignore_init_note.o ACFLAGS+= -DLOCORE CFLAGS+= -DSTRIP_FBSDID CFLAGS+= -fno-omit-frame-pointer CFLAGS+= -I${.CURDIR:H}/common \ -I${SRCTOP}/lib/libc/include CFLAGS_CRTS= -DSHARED ${PICFLAG} FILES= ${OBJS} FILESMODE= ${LIBMODE} FILESOWN= ${LIBOWN} FILESGRP= ${LIBGRP} FILESDIR= ${LIBDIR} # These FILES qualify as libraries for the purpose of LIBRARIES_ONLY. .undef LIBRARIES_ONLY CRT1SRC?= crt1_c.c CRT1OBJ?= CLEANFILES+= ${OBJS} ${CRT1OBJS} crt1_c.o gcrt1_c.o Scrt1_c.o CLEANFILES+= crti_s.o ${CRT1SRC:C/.[S|c]$/.o/} crt1.o: ${CRT1SRC:C/.[S|c]$/.o/} ${CRT1OBJS} ${CRT1OBJ} ${LD} ${_LDFLAGS} -o ${.TARGET} -r ${.ALLSRC:M*.o} -.if ${MACHINE_ARCH} == "i386" - ${OBJCOPY} --localize-symbol _start1 ${.TARGET} -.endif gcrt1_c.o: ${CRT1SRC} ${CC} ${CFLAGS} -DGCRT -c -o ${.TARGET} ${.CURDIR}/${CRT1SRC} gcrt1.o: gcrt1_c.o ${CRT1OBJS} ${CRT1OBJ} ${LD} ${_LDFLAGS} -o ${.TARGET} -r ${.ALLSRC:M*.o} Scrt1_c.o: ${CRT1SRC} ${CC} ${CFLAGS} -fPIC -DPIC -c -o ${.TARGET} ${.CURDIR}/${CRT1SRC} Scrt1.o: Scrt1_c.o ${CRT1OBJS} ${CRT1OBJ} ${LD} ${_LDFLAGS} -o ${.TARGET} -r ${.ALLSRC:M*.o} -.if ${MACHINE_ARCH} == "i386" - ${OBJCOPY} --localize-symbol _start1 ${.TARGET} -.endif crtbegin.o: crtbegin.c crtbeginS.o: crtbegin.c crtbeginT.o: crtbegin.c crtend.o: crtend.c crtendS.o: crtend.c crtbegin.o crtend.o crtbeginT.o: ${CC} ${CFLAGS} -I${.CURDIR} -c -o ${.TARGET} ${.ALLSRC:N*.h:[1]} crtbeginS.o crtendS.o: ${CC} ${CFLAGS} -I${.CURDIR} ${CFLAGS_CRTS} -c -o ${.TARGET} \ ${.ALLSRC:N*.h:[1]} crti_s.o: crti.S ${CC} ${CFLAGS} ${ACFLAGS} -c ${.ALLSRC:M*.S} -o ${.TARGET} crti.o: crti_s.o crtbrand.o ${LD} ${_LDFLAGS} -o ${.TARGET} -r ${.ALLSRC:M*.o} .endif .include "../Makefile.inc" diff --git a/lib/csu/i386/Makefile b/lib/csu/i386/Makefile index d8d0d3fd8f99..72be8b70ef19 100644 --- a/lib/csu/i386/Makefile +++ b/lib/csu/i386/Makefile @@ -1,9 +1,10 @@ # $FreeBSD$ .PATH: ${.CURDIR:H}/common CFLAGS+= -I${.CURDIR} -CRT1OBJS+= crt1_s.o +CRT1SRC= crt1_s.S +CRT1OBJ= crt1_c.o .include diff --git a/lib/csu/i386/crt1_c.c b/lib/csu/i386/crt1_c.c index d49c763749a3..7b28200cbd29 100644 --- a/lib/csu/i386/crt1_c.c +++ b/lib/csu/i386/crt1_c.c @@ -1,53 +1,34 @@ /* 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$ */ #include __FBSDID("$FreeBSD$"); -#include "libc_private.h" #include "csu_common.h" -void _start(char *, ...); -void _start1(void (*)(void), int, char *[]) __dead2; - -/* The entry function, C part. */ -void -_start1(void (*cleanup)(void), int argc, char *argv[]) -{ - char **env; - - env = argv + argc + 1; -#ifdef GCRT - __libc_start1_gcrt(argc, argv, env, cleanup, main, &eprol, &etext); -__asm__("eprol:"); -#else - __libc_start1(argc, argv, env, cleanup, main); -#endif -} - -__asm(".hidden _start1"); +void _start(char *, ...) __dead2; diff --git a/lib/csu/i386/crt1_s.S b/lib/csu/i386/crt1_s.S index 1bd9a4283987..f6e230a1a5a7 100644 --- a/lib/csu/i386/crt1_s.S +++ b/lib/csu/i386/crt1_s.S @@ -1,51 +1,95 @@ /*- * 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. * * 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$ */ #include __FBSDID("$FreeBSD$"); .text .align 4 .globl _start .type _start, @function _start: .cfi_startproc + .cfi_undefined %eip + popl %esi # Pop argc + .cfi_def_cfa_offset -4 + movl %esp,%edi # argv starts at stack top xorl %ebp,%ebp pushl %ebp - .cfi_def_cfa_offset 4 + .cfi_def_cfa_offset 0 movl %esp,%ebp - .cfi_offset %ebp,-8 + .cfi_offset %ebp,-4 .cfi_def_cfa_register %ebp andl $0xfffffff0,%esp # align stack - leal 8(%ebp),%eax - subl $4,%esp - pushl %eax # argv - pushl 4(%ebp) # argc + +#ifdef GCRT + subl $4,%esp # Align stack for 7 arguments + pushl $etext + pushl $eprol +eprol: +#else + subl $12,%esp # Align stack for 5 arguments +#endif /* GCRT */ + +#ifdef PIC + calll 1f +1: popl %ebx + addl $_GLOBAL_OFFSET_TABLE_+[.-1b],%ebx + leal main@GOTOFF(%ebx),%eax + pushl %eax +#else + pushl $main +#endif /* PIC */ + pushl %edx # rtld cleanup - call _start1 + /* env = argv + argc + 1 */ + movl %edi,%eax # env = argv + movl %esi,%ecx + shll $2,%ecx # argc * 4 + addl %ecx,%eax # env += argc + addl $4,%eax # env += 1 + pushl %eax # env + pushl %edi # argv + pushl %esi # argc + +#ifdef GCRT + /* + * __libc_start1_gcrt(argc, argv, env, cleanup, main, &eprol, &etext); + */ + calll __libc_start1_gcrt +#else + /* + * __libc_start1(argc, argv, env, cleanup, main); + */ +#ifdef PIC + calll __libc_start1@PLT +#else + calll __libc_start1 +#endif +#endif /* GCRT */ int3 .cfi_endproc .size _start, . - _start .section .note.GNU-stack,"",%progbits