From owner-svn-src-projects@freebsd.org Sun Aug 2 18:12:15 2020 Return-Path: Delivered-To: svn-src-projects@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 062663A43AF for ; Sun, 2 Aug 2020 18:12:15 +0000 (UTC) (envelope-from dim@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 "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4BKTct6S0Yz3WPM; Sun, 2 Aug 2020 18:12:14 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id C17D027777; Sun, 2 Aug 2020 18:12:14 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 072ICEYL065371; Sun, 2 Aug 2020 18:12:14 GMT (envelope-from dim@FreeBSD.org) Received: (from dim@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 072ICEm3065370; Sun, 2 Aug 2020 18:12:14 GMT (envelope-from dim@FreeBSD.org) Message-Id: <202008021812.072ICEm3065370@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: dim set sender to dim@FreeBSD.org using -f From: Dimitry Andric Date: Sun, 2 Aug 2020 18:12:14 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r363774 - projects/clang1100-import/contrib/llvm-project/libunwind/src X-SVN-Group: projects X-SVN-Commit-Author: dim X-SVN-Commit-Paths: projects/clang1100-import/contrib/llvm-project/libunwind/src X-SVN-Commit-Revision: 363774 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 02 Aug 2020 18:12:15 -0000 Author: dim Date: Sun Aug 2 18:12:14 2020 New Revision: 363774 URL: https://svnweb.freebsd.org/changeset/base/363774 Log: 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... Modified: projects/clang1100-import/contrib/llvm-project/libunwind/src/UnwindLevel1-gcc-ext.c Modified: projects/clang1100-import/contrib/llvm-project/libunwind/src/UnwindLevel1-gcc-ext.c ============================================================================== --- projects/clang1100-import/contrib/llvm-project/libunwind/src/UnwindLevel1-gcc-ext.c Sun Aug 2 18:07:16 2020 (r363773) +++ projects/clang1100-import/contrib/llvm-project/libunwind/src/UnwindLevel1-gcc-ext.c Sun Aug 2 18:12:14 2020 (r363774) @@ -234,6 +234,46 @@ _LIBUNWIND_EXPORT uintptr_t _Unwind_GetIPInfo(struct _ #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 *fd __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 * __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