-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core: Support heap-based trampolines.
1. Generate off-stack 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 is to be provided in libgcc, and is by-default _not_ compiled in unless the target specifically requires it, or you manually provide --enable-off-stack-trampolines when configuring gcc/libgcc. The gcc flag -foff-stack-trampolines 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: Andrew Burgess <andrew.burgess@embecosm.com> gcc/ChangeLog: * builtins.def (BUILT_IN_NESTED_PTR_CREATED): Define. (BUILT_IN_NESTED_PTR_DELETED): Ditto. * common.opt (foff-stack-trampolines): Add flag to control generation of heap-based trampoline instantiation. * tree-nested.c (convert_tramp_reference_op): Don't bother calling __builtin_adjust_trampoline for the off-stack case. (finalize_nesting_tree_1): Emit calls to __builtin_nested_...{created,deleted} if we're generating with -foff-stack-trampolines. * tree.c (build_common_builtin_nodes): Build __builtin_nested_...{created,deleted}. * dov/invoke.texi (-foff-stack-trampolines): Document. libgcc/ChangeLog: * configure.ac: Add configure parameter --enable-off-stack-trampolines, and do error checking if we've trying to enable off-stack trampolines for a platform that doesn't provide any such implementation. * configure: Regenerate. * libgcc-std.ver.in: Ditto. * libgcc2.h (__builtin_nested_func_ptr_created): Declare. (__builtin_nested_func_ptr_deleted): Ditto. 2. Add x86_64-linux support for off-stack trampolines Implement the __builtin_nested_func_ptr_{created,deleted} functions for the x86_64-linux platform. This serves to exercise the infrastructure added in libgcc (--enable-off-stack-trampolines) and gcc (-foff-stack-trampolines) in supporting off-stack trampoline generation, and is intended primarily for demonstration and debugging purposes. Co-authored-by: Andrew Burgess <andrew.burgess@embecosm.com> libgcc/ChangeLog: * config/i386/heap-trampoline.c: New file: Implement off-stack trampolines for x86_64. * config/i386/t-heap-trampoline: Add rule to build config/i386/heap-trampoline.c * config.host (x86_64-*-linux*): Handle --enable-off-stack-trampolines. * configure.ac (--enable-off-stack-trampolines): Permit setting for target x86_64-*-linux*. * configure: Regenerate. 3. Add aarch64-linux support for off-stack trampolines Implement the __builtin_nested_func_ptr_{created,deleted} functions for the aarch64-linux platform. This serves to exercise the infrastructure added in libgcc (--enable-off-stack-trampolines) and gcc (-foff-stack-trampolines) in supporting off-stack trampoline generation, and is intended primarily for demonstration and debugging purposes. Co-authored-by: Andrew Burgess <andrew.burgess@embecosm.com> libgcc/ChangeLog: * config/aarch64/heap-trampoline.c: New file: Implement off-stack trampolines for aarch64. * config/aarch64/t-heap-trampoline: Add rule to build config/aarch64/heap-trampoline.c * config.host (aarch64-*-linux*): Handle --enable-off-stack-trampolines. * configure.ac (--enable-off-stack-trampolines): Permit setting for target aarch64-*-linux*. * configure: Regenerate. 4. Darwin, aarch64, x86_64: Support heap trampolines. Implement the __builtin_nested_func_ptr_{created,deleted} functions for x86_64 and aarch64 Darwin. For aarch64 --enable-off-stack-trampolines is enabled by default, and -foff-stack-trampolines is enabled by default if we are on host MacOS version 11.x or greater. For x86_64 this is configure-time opt-in (and can be applied from 10.10 onwards) Co-authored-by: Andrew Burgess <andrew.burgess@embecosm.com> Co-authored-by: Iain Sandoe <iain@sandoe.co.uk> libgcc/ChangeLog: * config/aarch64/heap-trampoline.c (allocate_trampoline_page): Request for MAP_JIT in the case of __APPLE__. Provide __APPLE__ variant of aarch64_trampoline_insns that uses x16 as the chain pointer. (__builtin_nested_func_ptr_created): Call pthread_jit_write_protect_np() to toggle read/write permission on page. * config.host (aarch64*-*darwin* | arm64*-*darwin*): Handle --enable-off-stack-trampolines. * configure.ac (--enable-off-stack-trampolines): Permit setting for target aarch64*-*darwin* | arm64*-*darwin*, and set default to enabled. * configure: Regenerate.
- Loading branch information
Showing
18 changed files
with
650 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.