From nobody Wed Mar 23 15:30:57 2022 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 A60871A477F0; Wed, 23 Mar 2022 15:30:57 +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 4KNskn4FRRz4t92; Wed, 23 Mar 2022 15:30:57 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1648049457; 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=T4GNGRJnMzsrvCi2w4Yt1dZkn98MC+BqcNbXG9YLNow=; b=HkXTA7f84yOyHg+6/XO1QO1gPZcNvcKx7XXamxdODVGHeWM3lPwK/T+IST1Hz8rVS6f/PY k6zp5ZGXAwnLmdURvnnH0AMuK2ESPXPVmyz1cgtXDqSG2TQMGnmht+whfYElpPn1juFfUs tLPnfl6JIdC8sLnPaWZQg3jsIleL92r2XEyc6pLseTQTGU7n5GpgP4fV6bYa/f6g7rNb+v hYbZsRZQaYrRFDnl8vtwCuMSoFX20lCCotITACuqqj+Ds7KE9ym5FBrirnkxBmY7WDlBh8 0O94PX5MgAvyhnUrz57E/y53oAIKsoCmFfKGdW4WQH2hb28/gVNKXeV2Cm5a8g== 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 697C225F55; Wed, 23 Mar 2022 15:30:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 22NFUves063860; Wed, 23 Mar 2022 15:30:57 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 22NFUvwp063859; Wed, 23 Mar 2022 15:30:57 GMT (envelope-from git) Date: Wed, 23 Mar 2022 15:30:57 GMT Message-Id: <202203231530.22NFUvwp063859@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Andrew Turner Subject: git: 16d5f9a1649e - main - Add an implementation of .mcount on arm64 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: andrew X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 16d5f9a1649e6a3e5841c6c41d6af9430ed9f064 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1648049457; 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=T4GNGRJnMzsrvCi2w4Yt1dZkn98MC+BqcNbXG9YLNow=; b=Bmx3BJCc/Nd54b4vC7Odl5d/pEHafzIky4+TVwFNMb5kOKUQeGdas01gFcCyNOBlAFbLNu dJAmsc919O/5riRkjPvTuci2Jr7Vwf+aHEM115tuwk39F9i89STd/gs5ALke9HLojz97nS fqfa+GZDpkR+fpZ5+CJd0/dDkJ2PL6aA9rGAYr72xYw1jPC5UCphBa7YJNPtMI1aMh2uSX InNpRa5rxZFzPEPUgEiEhCOj0CAmkcbzok/atQGS9Unx8nO6YyIF0RcxaWMd7FusssCPTG X9CrNhE14KBNjmU14nfkZOA4/YRHTc1RSvrmRpawwwcnJPLi6xeLSlnED6cVNA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1648049457; a=rsa-sha256; cv=none; b=Nr4S+GSWZqH4Prusa5aQKDVE7ER3aqr8JiQsPxav6W8LMhCFgGZD8wGWl/4n7MMuFVEZgh 5zTRn6V4DYqs5vbZWTTzMNPfr7Bo1TmDhny6a8J8af1GWKX0wBo4O3R/xQUcJw7TbEmWN9 dBzDLm2+rtz7xkyGtfu8l1yUMOqhBFXAuc92+pYsJE/nNROhPtz7nQTZjeXH3b6S2W0KSc D5hhns7LokiqMIzGdaNswR6P5DzAVU9qeBYp8k9GAfTXA+icD7AcN+PILs/d3D99y+iBFI BFghU8RrfQ+wjqCL0Br2tlHzJB0vNiyIKP+p3NatuXeotCL3TUjTXsMGPCvL/w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=16d5f9a1649e6a3e5841c6c41d6af9430ed9f064 commit 16d5f9a1649e6a3e5841c6c41d6af9430ed9f064 Author: Andrew Turner AuthorDate: 2022-03-22 15:46:15 +0000 Commit: Andrew Turner CommitDate: 2022-03-23 15:16:59 +0000 Add an implementation of .mcount on arm64 To support cc -pg on arm64 we need to implement .mcount. As clang and gcc think it is function like it just needs to load the arguments to _mcount and call it. On gcc the first argument is passed in x0, however this is missing on clang so we need to load it from the stack. As it's the caller return address this will be at a known location. PR: 262709 Reviewed by: emaste (earlier version) Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D34634 --- lib/libc/aarch64/Symbol.map | 1 + sys/arm64/include/profile.h | 45 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/lib/libc/aarch64/Symbol.map b/lib/libc/aarch64/Symbol.map index 4214db12ed5f..0a5d8782d3ac 100644 --- a/lib/libc/aarch64/Symbol.map +++ b/lib/libc/aarch64/Symbol.map @@ -11,6 +11,7 @@ FBSD_1.0 { /* PSEUDO syscalls */ _exit; + .mcount; _setjmp; _longjmp; fabs; diff --git a/sys/arm64/include/profile.h b/sys/arm64/include/profile.h index 86a9703437e7..f5f5caa1faa3 100644 --- a/sys/arm64/include/profile.h +++ b/sys/arm64/include/profile.h @@ -44,8 +44,51 @@ typedef u_long fptrdiff_t; typedef __uintfptr_t uintfptr_t; -#define _MCOUNT_DECL void mcount +#define _MCOUNT_DECL \ +static void _mcount(uintfptr_t frompc, uintfptr_t selfpc) __used; \ +static void _mcount + +#ifdef __GNUCLIKE_ASM +/* + * Call into _mcount. On arm64 the .mcount is a function so callers will + * handle caller saved registers. As we don't directly touch any callee + * saved registers we can just load the two arguments and use a tail call + * into the MI _mcount function. + * + * When building with gcc frompc will be in x0, however this is not the + * case on clang. As such we need to load it from the stack. As long as + * the caller follows the ABI this will load the correct value. + */ +#define MCOUNT __asm( \ +" .text \n" \ +" .align 6 \n" \ +" .type .mcount,#function \n" \ +" .globl .mcount \n" \ +" .mcount: \n" \ +" .cfi_startproc \n" \ + /* Load the caller return address as frompc */ \ +" ldr x0, [x29, #8] \n" \ + /* Use our return address as selfpc */ \ +" mov x1, lr \n" \ +" b _mcount \n" \ +" .cfi_endproc \n" \ +" .size .mcount, . - .mcount \n" \ + ); +#if 0 +/* + * If clang passed frompc correctly we could implement it like this, however + * all clang versions we care about would need to be fixed before we could + * make this change. + */ +void +mcount(uintfptr_t frompc) +{ + _mcount(frompc, __builtin_return_address(0)); +} +#endif +#else #define MCOUNT +#endif #endif /* !_KERNEL */