From nobody Wed Dec 22 10:05:27 2021 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 65D8119048C0; Wed, 22 Dec 2021 10:05:31 +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 4JJpqC5Gtzz4Xnr; Wed, 22 Dec 2021 10:05:27 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 549D91B1D1; Wed, 22 Dec 2021 10:05:27 +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 1BMA5RQ2091374; Wed, 22 Dec 2021 10:05:27 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1BMA5RU6091373; Wed, 22 Dec 2021 10:05:27 GMT (envelope-from git) Date: Wed, 22 Dec 2021 10:05:27 GMT Message-Id: <202112221005.1BMA5RU6091373@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dimitry Andric Subject: git: 96ac81cdf020 - stable/12 - Reapply r310365 (by emaste): 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: dim X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 96ac81cdf020b9fc9d4ff6e01681cf46ba55d3d8 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1640167528; 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=kvanAcTYVuxyyJdzU9xGsns2tzJl9wBbQX+jgBbQQDg=; b=stUtrjYKugDx8RBwUkmkUmnLJKJXNxLxV8yW7CRXKOQQQ49gmC79BvxiLhZschPd9YtM4Y AKWIcd5Mw7r2hLsOVAIbtQ17DPUeCM52e+vArj1ksyHRXYuasuYcFNuGl6Dj/+nx/1/G9n HIx+fvgReRQdNAJlwslxtpxDwOziETeVOoDqvEnXb6ujYNc5AW2wiKpo/MnlInRXfHLwWv AXBrvyOjK/4YBH9VrzlQZuTcD33STC6amhHvFZZGLKVFQhy9uBhqdSkJ0kHkmkF1BprJsB oO4OD5ZHL5cf12BHyaO2JsIyZWpyKwnOcKleO+hhw/+13pF9aEJ5/tF4ZF/OdQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1640167528; a=rsa-sha256; cv=none; b=KRPlzRmFrkKx1paf5puSj4zWoHrYyUsGAANRQ3475UEx+6CB/Gj3LVyHVLdFNK1wszLNpb hFkprjEK4nx7/8xvr4CihBqPhAumQQUyNP0dxfWOucZrPiWub/0VzuWQfyfoEsJsWlpqu/ 1ydYHN4Lw430v/rbUxAZqS6Ioc5Cg6C7g4HSNByYtj3fc0XUqdYmaavrwNiUzrHZby0SyT J0ebA3N+y3LIIMi3AfpDblXWtuE2eODaOpFWLVSPKEsSZUs6HMKzxwIkiu+uul6U1G1TI3 KYxyMl17zGQe6qK93905SrqhScocrB7dJvfzFwCTAeIw1dY3nYvQ6FaFV0tVUQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by dim: URL: https://cgit.FreeBSD.org/src/commit/?id=96ac81cdf020b9fc9d4ff6e01681cf46ba55d3d8 commit 96ac81cdf020b9fc9d4ff6e01681cf46ba55d3d8 Author: Dimitry Andric AuthorDate: 2020-08-02 18:12:14 +0000 Commit: Dimitry Andric CommitDate: 2021-12-22 09:58:11 +0000 Reapply r310365 (by emaste): libunwind: make __{de,}register_frame compatible with libgcc API The libgcc __register_frame and __deregister_frame functions take a pointer to a set of FDE/CIEs, terminated by an entry where length is 0. In Apple's libunwind implementation the pointer is taken to be to a single FDE. I suspect this was just an Apple bug, compensated by Apple- specific code in LLVM. See lib/ExecutionEngine/RuntimeDyld/RTDyldMemoryManager.cpp and http://lists.llvm.org/pipermail/llvm-dev/2013-April/061737.html for more detail. This change is based on the LLVM RTDyldMemoryManager.cpp. It should later be changed to be alignment-safe. Reported by: dim Reviewed by: dim Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D8869 Reapply r351610: Update libunwind custom frame register and deregister functions for FreeBSD: use the new doubly underscored names for unw_add_dynamic_fde and unw_remove_dynamic_fde. NOTE: this should be upstreamed... (cherry picked from commit 9f287522cec9feac040d7cb845a440a8f6b7b90e) --- .../libunwind/src/UnwindLevel1-gcc-ext.c | 42 +++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/contrib/llvm-project/libunwind/src/UnwindLevel1-gcc-ext.c b/contrib/llvm-project/libunwind/src/UnwindLevel1-gcc-ext.c index 310b836d129e..30f9cabf241f 100644 --- a/contrib/llvm-project/libunwind/src/UnwindLevel1-gcc-ext.c +++ b/contrib/llvm-project/libunwind/src/UnwindLevel1-gcc-ext.c @@ -234,6 +234,46 @@ _LIBUNWIND_EXPORT uintptr_t _Unwind_GetIPInfo(struct _Unwind_Context *context, #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) +#if defined(__FreeBSD__) + +// Based on LLVM's lib/ExecutionEngine/RuntimeDyld/RTDyldMemoryManager.cpp +// and XXX should be fixed to be alignment-safe. +static void processFDE(const char *addr, bool isDeregister) { + uint64_t length; + while ((length = *((const uint32_t *)addr)) != 0) { + const char *p = addr + 4; + if (length == 0xffffffff) { + length = *((const uint64_t *)p); + p += 8; + } + uint32_t offset = *((const uint32_t *)p); + if (offset != 0) { + if (isDeregister) + __unw_remove_dynamic_fde((unw_word_t)(uintptr_t)addr); + else + __unw_add_dynamic_fde((unw_word_t)(uintptr_t)addr); + } + addr = p + length; + } +} + +/// Called by programs with dynamic code generators that want to register +/// dynamically generated FDEs, with a libgcc-compatible API. + +_LIBUNWIND_EXPORT void __register_frame(const void *addr) { + _LIBUNWIND_TRACE_API("__register_frame(%p)", addr); + processFDE(addr, false); +} + +/// Called by programs with dynamic code generators that want to unregister +/// dynamically generated FDEs, with a libgcc-compatible API. +_LIBUNWIND_EXPORT void __deregister_frame(const void *addr) { + _LIBUNWIND_TRACE_API("__deregister_frame(%p)", addr); + processFDE(addr, true); +} + +#else // defined(__FreeBSD__) + /// Called by programs with dynamic code generators that want /// to register a dynamically generated FDE. /// This function has existed on Mac OS X since 10.4, but @@ -243,7 +283,6 @@ _LIBUNWIND_EXPORT void __register_frame(const void *fde) { __unw_add_dynamic_fde((unw_word_t)(uintptr_t)fde); } - /// Called by programs with dynamic code generators that want /// to unregister a dynamically generated FDE. /// This function has existed on Mac OS X since 10.4, but @@ -253,6 +292,7 @@ _LIBUNWIND_EXPORT void __deregister_frame(const void *fde) { __unw_remove_dynamic_fde((unw_word_t)(uintptr_t)fde); } +#endif // defined(__FreeBSD__) // The following register/deregister functions are gcc extensions. // They have existed on Mac OS X, but have never worked because Mac OS X