[libunwind] On Darwin, add a callback-based lookup scheme for JIT'd unwind info.
This commit adds support for a new callback-based lookup scheme for unwind info that was inspired by the `_dyld_find_unwind_info_sections` SPI that libunwind uses to find unwind-info in non-JIT'd frames. From llvm-project/libunwind/src/AddressSpace.hpp: ``` struct dyld_unwind_sections { const struct mach_header* mh; const void* dwarf_section; uintptr_t dwarf_section_length; const void* compact_unwind_section; uintptr_t compact_unwind_section_length; }; extern bool _dyld_find_unwind_sections(void *, dyld_unwind_sections *); ``` During unwinding libunwind calls `_dyld_find_unwind_sections` to both find unwind section addresses and identify the subarchitecture for frames (via the MachO-header pointed to by the mh field). This commit introduces two new libunwind SPI functions: ``` struct unw_dynamic_unwind_sections { unw_word_t dso_base; unw_word_t dwarf_section; size_t dwarf_section_length; unw_word_t compact_unwind_section; size_t compact_unwind_section_length; }; typedef int (*unw_find_dynamic_unwind_sections)( unw_word_t addr, struct unw_dynamic_unwind_sections *info); // Returns UNW_ESUCCESS if successfully registered, UNW_EINVAL for duplicate // registrations, and UNW_ENOMEM to indicate too many registrations. extern int __unw_add_find_dynamic_unwind_sections( unw_find_dynamic_unwind_sections find_dynamic_unwind_sections); // Returns UNW_ESUCCESS if successfully deregistered, UNW_EINVAL to indicate // no such registration. extern int __unw_remove_find_dynamic_unwind_sections( unw_find_dynamic_unwind_sections find_dynamic_unwind_sections); ``` These can be used to register and deregister callbacks that have a similar signature to `_dyld_find_unwind_sections`. During unwinding if `_dyld_find_unwind_sections` returns false (indicating that no frame info was found by dyld) then registered callbacks are run in registration order until either the unwind info is found or the end of the list is reached. With this commit, and by implementing the find-unwind-info callback in the ORC runtime in LLVM, we (1) enable support for registering JIT'd compact-unwind info with libunwind*, (2) provide a way to identify the subarchitecture for each frame (by returning a pointer to a JIT'd MachO header), and (3) delegate tracking of unwind info to the callback, which may be able to implement more efficient address-based lookup than libunwind. * JITLink does not process or register compact unwind info yet, so this patch does not fully enable compact unwind info in ORC, it simply provides some necessary plumbing. JITLink support for compact unwind should land some time in the LLVM 17 development cycle. Reviewed By: pete Differential Revision: https://reviews.llvm.org/D142176
Loading
Please sign in to comment