core: Support heap-based trampolines
Generate heap-based nested function trampolines Add support for allocating nested function trampolines on an executable heap rather than on the stack. This is motivated by targets such as AArch64 Darwin, which globally prohibit executing code on the stack. The target-specific routines for allocating and writing trampolines are to be provided in libgcc. The gcc flag -ftrampoline-impl controls whether to generate code that instantiates trampolines on the stack, or to emit calls to __builtin_nested_func_ptr_created and __builtin_nested_func_ptr_deleted. Note that this flag is completely independent of libgcc: If libgcc is for any reason missing those symbols, you will get a link failure. This implementation imposes some implicit restrictions as compared to stack trampolines. longjmp'ing back to a state before a trampoline was created will cause us to skip over the corresponding __builtin_nested_func_ptr_deleted, which will leak trampolines starting from the beginning of the linked list of allocated trampolines. There may be scope for instrumenting longjmp/setjmp to trigger cleanups of trampolines. Co-Authored-By:Maxim Blinov <maxim.blinov@embecosm.com> Co-Authored-By:
Iain Sandoe <iain@sandoe.co.uk> Co-Authored-By:
Francois-Xavier Coudert <fxcoudert@gcc.gnu.org> gcc/ChangeLog: * builtins.def (BUILT_IN_NESTED_PTR_CREATED): Define. (BUILT_IN_NESTED_PTR_DELETED): Ditto. * common.opt (ftrampoline-impl): Add option to control generation of trampoline instantiation (heap or stack). * coretypes.h: Define enum trampoline_impl. * tree-nested.cc (convert_tramp_reference_op): Don't bother calling __builtin_adjust_trampoline for heap trampolines. (finalize_nesting_tree_1): Emit calls to __builtin_nested_...{created,deleted} if we're generating with -ftrampoline-impl=heap. * tree.cc (build_common_builtin_nodes): Build __builtin_nested_...{created,deleted}. * doc/invoke.texi (-ftrampoline-impl): Document.
Showing
- gcc/builtins.def 2 additions, 0 deletionsgcc/builtins.def
- gcc/common.opt 16 additions, 1 deletiongcc/common.opt
- gcc/coretypes.h 6 additions, 0 deletionsgcc/coretypes.h
- gcc/doc/invoke.texi 16 additions, 1 deletiongcc/doc/invoke.texi
- gcc/tree-nested.cc 104 additions, 17 deletionsgcc/tree-nested.cc
- gcc/tree.cc 17 additions, 0 deletionsgcc/tree.cc
Loading
Please register or sign in to comment