From nobody Thu Jun 29 16:39:06 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 4QsPKk3dw1z4jv47; Thu, 29 Jun 2023 16:39:06 +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 4QsPKk37r7z3FTN; Thu, 29 Jun 2023 16:39:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1688056746; 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=XSWVtASo7wap+HlLAOP9FmTkPLDgWDPObkk6SwAsz2s=; b=fkFS2T0QcxnbNnx8cqoQEzar2IjFzkTXELjC6h4wtkpDpl0C/95FT33eVLJC5oP5KQ3u79 rb60FyFTjnA6l4XAZTGL4oSWIsHel6CIJRevQaEaLjFMyZ+yrpfHX6c7FEu9EDmDMzkaJu zLO7swOi8Hf8+iOQQo4ccirRG59u3oiwpBp3wKLd5A6KoQQ+DQOebPJJrKt8lZ2HF05aMs y5zMHev4yj8R/aPM/LKtk7HezxRNc9Qayc1QUAFRW0k8bDVLhLyYhXK2KqD7/oExp/JUZk J43CmCnoxp3PN1rciQ96yubxPgNr2nDX4tAwIXwlZC7HD6OaEP37SBy9wNIvGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1688056746; 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=XSWVtASo7wap+HlLAOP9FmTkPLDgWDPObkk6SwAsz2s=; b=skcLH0sbzEUfILmOll2D0BaIyRF1Bgk2ZwOgpHmG3fp/FsRQgCyC+LA8reSPT6nO7wqMae CL+3G6gPVnD2Vyasj8TEPpckhCZ0JA/gBGroa1KMy/nDpLGFdM/XeBzf3iNKmjLLhW7QuN OicYgDC5e0BdvOFfA9BTy5VVgy/uMpGyYer9oTnpXLlWFWhL/4wApqPM4ZPkYtI8YKYL3M MCCPB7WbpcE8jjiJ3HTKuDm8HyAUaUo+Q2YQmlp4QNHOQULs8YRHD68BEodA+RzRZ1YjMy F1/S9PKWR41dO34hgMArjC6mjps8qdUcvTFPVRQtMzCdaDRT4E8gLLD7rwDupw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1688056746; a=rsa-sha256; cv=none; b=uolYkqYp1OnaQLnchPWPV8wr2f8FSMhjv7sQvjSK2Xjt4es4geTbQqIivdhwnMM/Ec4uJI nWpZnPVP7etboVqZAavXHvM6Nb4/56yXqljgkJsRuviT9OU3UW2MoboXGAfOL5lEbXDgyH cIkNvkSJkmPdTKjUp5YxNHmoNE834NPXiD+SOBfRqfCcCQjq9rNkY+PP2TrWrUFE3tpgJU zX+AKdczonDc94Kfelvt6Ub1E2zUWqNSspYYqXMr7+qlxsMZzrgutuCLJRu9rlmGpPdSob uhzhq7iODWZ6L8qLbDaT1IRVL8NnPR0+g4MOSnamjBjf4kg7QWXBDSXxl3LzUA== 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 4QsPKk1qZGzP5v; Thu, 29 Jun 2023 16:39:06 +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 35TGd6cm003463; Thu, 29 Jun 2023 16:39:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 35TGd695003462; Thu, 29 Jun 2023 16:39:06 GMT (envelope-from git) Date: Thu, 29 Jun 2023 16:39:06 GMT Message-Id: <202306291639.35TGd695003462@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: c969310c992a - main - csu: Implement _start using as to satisfy unwinders on x86_64 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: c969310c992a12459ed4025c1cd8b22f29c763b5 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by dchagin: URL: https://cgit.FreeBSD.org/src/commit/?id=c969310c992a12459ed4025c1cd8b22f29c763b5 commit c969310c992a12459ed4025c1cd8b22f29c763b5 Author: Dmitry Chagin AuthorDate: 2023-06-29 16:34:39 +0000 Commit: Dmitry Chagin CommitDate: 2023-06-29 16:34:39 +0000 csu: Implement _start using as to satisfy unwinders on x86_64 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. This requires the crt code be built with unwind tables, for that remove -fno-asynchronous-unwind-tables to enable unwind tables generation. PR: 241562, 246322, 246537 Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D40780 --- lib/csu/Makefile.inc | 20 ++++++------ lib/csu/amd64/Makefile | 3 ++ lib/csu/amd64/crt1_c.c | 22 ------------- lib/csu/amd64/crt1_s.S | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 102 insertions(+), 31 deletions(-) diff --git a/lib/csu/Makefile.inc b/lib/csu/Makefile.inc index 1633fa3dc3ea..ee60c3968b87 100644 --- a/lib/csu/Makefile.inc +++ b/lib/csu/Makefile.inc @@ -20,7 +20,6 @@ CRT1OBJS+= crtbrand.o feature_note.o ignore_init_note.o ACFLAGS+= -DLOCORE CFLAGS+= -DSTRIP_FBSDID -CFLAGS+= -fno-asynchronous-unwind-tables CFLAGS+= -fno-omit-frame-pointer CFLAGS+= -I${.CURDIR:H}/common \ -I${SRCTOP}/lib/libc/include @@ -35,25 +34,28 @@ 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 +CLEANFILES+= crti_s.o ${CRT1SRC:C/.[S|c]$/.o/} -crt1.o: crt1_c.o ${CRT1OBJS} +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: crt1_c.c - ${CC} ${CFLAGS} -DGCRT -c -o ${.TARGET} ${.CURDIR}/crt1_c.c +gcrt1_c.o: ${CRT1SRC} + ${CC} ${CFLAGS} -DGCRT -c -o ${.TARGET} ${.CURDIR}/${CRT1SRC} -gcrt1.o: gcrt1_c.o ${CRT1OBJS} +gcrt1.o: gcrt1_c.o ${CRT1OBJS} ${CRT1OBJ} ${LD} ${_LDFLAGS} -o ${.TARGET} -r ${.ALLSRC:M*.o} -Scrt1_c.o: crt1_c.c - ${CC} ${CFLAGS} -fPIC -DPIC -c -o ${.TARGET} ${.CURDIR}/crt1_c.c +Scrt1_c.o: ${CRT1SRC} + ${CC} ${CFLAGS} -fPIC -DPIC -c -o ${.TARGET} ${.CURDIR}/${CRT1SRC} -Scrt1.o: Scrt1_c.o ${CRT1OBJS} +Scrt1.o: Scrt1_c.o ${CRT1OBJS} ${CRT1OBJ} ${LD} ${_LDFLAGS} -o ${.TARGET} -r ${.ALLSRC:M*.o} .if ${MACHINE_ARCH} == "i386" ${OBJCOPY} --localize-symbol _start1 ${.TARGET} diff --git a/lib/csu/amd64/Makefile b/lib/csu/amd64/Makefile index 9f3afb4cc1a0..370d206259d4 100644 --- a/lib/csu/amd64/Makefile +++ b/lib/csu/amd64/Makefile @@ -5,4 +5,7 @@ CFLAGS+= -I${.CURDIR} CFLAGS+= -fno-omit-frame-pointer +CRT1SRC= crt1_s.S +CRT1OBJ= crt1_c.o + .include diff --git a/lib/csu/amd64/crt1_c.c b/lib/csu/amd64/crt1_c.c index 9fe227f2e433..8c57e36becfd 100644 --- a/lib/csu/amd64/crt1_c.c +++ b/lib/csu/amd64/crt1_c.c @@ -29,26 +29,4 @@ #include __FBSDID("$FreeBSD$"); -#include "libc_private.h" #include "csu_common.h" - -void _start(char **, void (*)(void)) __dead2; - -/* The entry function. */ -void -_start(char **ap, void (*cleanup)(void)) -{ - int argc; - char **argv; - char **env; - - argc = *(long *)(void *)ap; - argv = ap + 1; - env = ap + 2 + argc; -#ifdef GCRT - __libc_start1_gcrt(argc, argv, env, cleanup, main, &eprol, &etext); -__asm__("eprol:"); -#else - __libc_start1(argc, argv, env, cleanup, main); -#endif -} diff --git a/lib/csu/amd64/crt1_s.S b/lib/csu/amd64/crt1_s.S new file mode 100644 index 000000000000..0c1c3b960bda --- /dev/null +++ b/lib/csu/amd64/crt1_s.S @@ -0,0 +1,88 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (C) 2023 Dmitry Chagin + * + * 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 AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. + */ + +#include + + + .text + .align 8 + + /* + * The program entry point + * %rdi %rsi + * void _start(char **ap, void (*cleanup)(void)) __dead2 + */ + .globl _start + .type _start, @function +_start: + .cfi_startproc + .cfi_undefined %rip /* Terminate call chain. */ + pushq %rbp /* Align stack, terminate call chain. */ + .cfi_def_cfa_offset 8 + movq %rsp, %rbp + .cfi_offset %rbp, -16 + .cfi_def_cfa_register %rbp +#ifdef GCRT + subq $16, %rsp +#endif + movq %rsi, %rcx + movq %rdi, %rsi /* argv = ap */ + addq $8, %rsi /* argv += 1 */ + movq %rdi, %rdx /* env = ap */ + addq $16, %rdx /* env += 2 */ + movslq (%rdi), %rax + movl %eax, %edi /* argc = *(long *)(void *)ap */ + shlq $3, %rax + addq %rax, %rdx /* env += argc */ +#ifdef PIC + /* + * XXX. %rip relative addressing does not intended to use in the + * large memory model due to offset from %rip is limited to 32 bits. + */ + leaq main(%rip), %r8 +#else + movabsq $main, %r8 +#endif +#ifdef GCRT + movabsq $eprol, %r9 + movabsq $etext, %rax + movq %rax, (%rsp) + /* + * %edi %rsi %rdx %rcx %r8 %r9 (%rsp) + * __libc_start1_gcrt(argc, argv, env, cleanup, main, &eprol, &etext) + */ + callq __libc_start1_gcrt +eprol: +#else + /* __libc_start1(argc, argv, env, cleanup, main) */ + callq __libc_start1 +#endif + int3 + .cfi_endproc + .size _start, . - _start + + .section .note.GNU-stack,"",%progbits