Date: Fri, 20 Jan 2017 02:48:52 +0000 (UTC) From: Ed Maste <emaste@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r312448 - stable/11/contrib/llvm/projects/libunwind/src Message-ID: <201701200248.v0K2mqS4077267@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: emaste Date: Fri Jan 20 02:48:52 2017 New Revision: 312448 URL: https://svnweb.freebsd.org/changeset/base/312448 Log: MFC r310365: 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. Sponsored by: The FreeBSD Foundation Modified: stable/11/contrib/llvm/projects/libunwind/src/UnwindLevel1-gcc-ext.c Directory Properties: stable/11/ (props changed) Modified: stable/11/contrib/llvm/projects/libunwind/src/UnwindLevel1-gcc-ext.c ============================================================================== --- stable/11/contrib/llvm/projects/libunwind/src/UnwindLevel1-gcc-ext.c Fri Jan 20 02:46:14 2017 (r312447) +++ stable/11/contrib/llvm/projects/libunwind/src/UnwindLevel1-gcc-ext.c Fri Jan 20 02:48:52 2017 (r312448) @@ -224,6 +224,47 @@ _LIBUNWIND_EXPORT uintptr_t _Unwind_GetI #if _LIBUNWIND_SUPPORT_DWARF_UNWIND +#ifdef __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 + /// 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,6 +284,7 @@ _LIBUNWIND_EXPORT void __deregister_fram _unw_remove_dynamic_fde((unw_word_t)(uintptr_t) fde); } +#endif // The following register/deregister functions are gcc extensions. // They have existed on Mac OS X, but have never worked because Mac OS X
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201701200248.v0K2mqS4077267>