From nobody Tue Jul 11 12:12:20 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4R0frP0RSMz2tnJt; Tue, 11 Jul 2023 12:12:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4R0frN6hLpz3v7K; Tue, 11 Jul 2023 12:12:20 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1689077541; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ZfHWb+xPXMZ6ic2Sn09MT3DE1/G+KmUA7+AO18pWhn4=; b=s3K2cQT5gj6/chlN8YBUaLPlfOpxLzKaUX76K/khE5vviPRuw0GQW9Tn18faoFcTU1BI88 bgM1rQ3TbFaPF9SKTFqhiKMT0PwNca8IekFd0b+i/OSOyP/xhYGrVaahA50rEpfXIqCrMb W/3vbwSHJLoblfvpP5sRw798nNZFLBmRFnIYLbB1+I/zIRr/0GEj6NepCuv72tlVZY0uaV HXIjWp+gZj9DYR457eK+CTb+EUihqvwLO7Hr57aHnuctC3FBh/dBp3Wr80hVC0WH52HU6c k9+mM2FnEFfnc0a+niM9NxksOzrXksn+GkpUflXIHAF9pk2bYuQScRtOlAbQ1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1689077541; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ZfHWb+xPXMZ6ic2Sn09MT3DE1/G+KmUA7+AO18pWhn4=; b=fvoRjCkuoYkuPemrrby5+jGpy1wkpKMuHZ69CYbFhu7aryyUD6djYxE2iZsRKFkNKsopLI jh4Zh6ObsfFNmOe6sPqYRLxiXGjWGpWCebnEGGKOUV+Vb+KngQ0oj6rKDw22u9BbMhNMHR 5jetp3rxpBB0zNW6sEj84BsMS+FCL5rIDdHwCrjasFHfyvUziiYVOjhkSQ2wsb/ooPPPRV mf/Y4qtCUmmkT0K2pvlDjRDbaXYyOiBQDB/8YV99TVGMNkP6v5ZHvZNBGbRN9982Xv2g0S BpxNEM2BmA7Bg78RjxDFY1LzciDW3rFRosDi9zG9yD6zrnQREi0X5rzUNWkpsw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1689077541; a=rsa-sha256; cv=none; b=EeJ5LZbBnDkEq0j0ckxGzjJf6wqO1KBC1aIErJyJTg7Q/4sxfyUwz7x1lmUHGs2w9wLteg AFiPDz10fIQF6KFddIh+bh3VKGKavtb832eXaXgILohGQ7h6h8mK8ttvVaMOoXf2evavIv fUN9ZkCSFtOMtzaaIQ1TmJjnv4+mPezKCuj97T8rCcmkpOpda3c+jeYBg54IN0FlPT8LSt KTL//P1QCakj/KvwGUHLwTAx6LmOfASsZfyl2+SDE4kaPTNWzyohANz30sECva3nIAjxFo dOyhw0IEU8QMGLHnRDESiWNx+4JjqjFS6g6GdKEWJqEb+mSAH0CZKG6p0l8V1w== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4R0frN5Z2czQss; Tue, 11 Jul 2023 12:12:20 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 36BCCKqe025149; Tue, 11 Jul 2023 12:12:20 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 36BCCKR7025148; Tue, 11 Jul 2023 12:12:20 GMT (envelope-from git) Date: Tue, 11 Jul 2023 12:12:20 GMT Message-Id: <202307111212.36BCCKR7025148@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dmitry Chagin Subject: git: d744a37a3ad4 - main - csu: Implement _start using as to satisfy unwinders on i386 List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dchagin X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: d744a37a3ad4be9d1f748258195f9d654c3cb2ae Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by dchagin: URL: https://cgit.FreeBSD.org/src/commit/?id=d744a37a3ad4be9d1f748258195f9d654c3cb2ae commit d744a37a3ad4be9d1f748258195f9d654c3cb2ae Author: Dmitry Chagin AuthorDate: 2023-07-11 12:12:01 +0000 Commit: Dmitry Chagin CommitDate: 2023-07-11 12:12:01 +0000 csu: Implement _start using as to satisfy unwinders on i386 The right unwinding stop indicator should be CFI-undefined PC. https://dwarfstd.org/doc/Dwarf3.pdf - page 118: If a Return Address register is defined in the virtual unwind table, and its rule is undefined (for example, by DW_CFA_undefined), then there is no return address and no call address, and the virtual unwind of stack activations is complete. The hack localizing _start1 symbol removed. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D40624 --- lib/csu/Makefile.inc | 6 ------ lib/csu/i386/Makefile | 3 ++- lib/csu/i386/crt1_c.c | 21 +------------------ lib/csu/i386/crt1_s.S | 58 ++++++++++++++++++++++++++++++++++++++++++++------- 4 files changed, 54 insertions(+), 34 deletions(-) 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 @@ -42,9 +42,6 @@ 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} @@ -57,9 +54,6 @@ Scrt1_c.o: ${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 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 @@ -4,6 +4,7 @@ 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 @@ -29,25 +29,6 @@ #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 @@ -31,19 +31,63 @@ __FBSDID("$FreeBSD$"); .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