-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libunwind] Add CMake option to enable execute-only code generation on AArch64 #140554
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…n AArch64 For a full toolchain supporting execute-only code generation the runtime libraries also need to be pre-compiled with it enabled. For libunwind this can now be enabled with the `LIBUNWIND_EXECUTE_ONLY_CODE` CMake option during build configuration. The build option can only be enabled for a runtimes build of libunwind, because a recent version of Clang is needed to correctly compile assembly files with execute-only code support. Related RFC: https://discourse.llvm.org/t/rfc-execute-only-code-support-for-runtime-libraries-on-aarch64/86180
@llvm/pr-subscribers-libunwind Author: Csanád Hajdú (Il-Capitano) ChangesFor a full toolchain supporting execute-only code generation the runtime libraries also need to be pre-compiled with it enabled. For libunwind this can now be enabled with the The build option can only be enabled for a runtimes build of libunwind, because a recent version of Clang is needed to correctly compile assembly files with execute-only code support. Related RFC: https://discourse.llvm.org/t/rfc-execute-only-code-support-for-runtime-libraries-on-aarch64/86180 Full diff: https://github.com/llvm/llvm-project/pull/140554.diff 3 Files Affected:
diff --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt
index e27f3c2e2fc17..75195fe022d4b 100644
--- a/libunwind/CMakeLists.txt
+++ b/libunwind/CMakeLists.txt
@@ -55,6 +55,7 @@ option(LIBUNWIND_USE_FRAME_HEADER_CACHE "Cache frame headers for unwinding. Requ
option(LIBUNWIND_REMEMBER_HEAP_ALLOC "Use heap instead of the stack for .cfi_remember_state." OFF)
option(LIBUNWIND_INSTALL_HEADERS "Install the libunwind headers." ON)
option(LIBUNWIND_ENABLE_FRAME_APIS "Include libgcc-compatible frame apis." OFF)
+option(LIBUNWIND_EXECUTE_ONLY_CODE "Compile libunwind as execute-only." OFF)
set(LIBUNWIND_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
"Define suffix of library directory name (32/64)")
@@ -109,6 +110,11 @@ endif()
option(LIBUNWIND_HIDE_SYMBOLS
"Do not export any symbols from the static library." ${LIBUNWIND_DEFAULT_HIDE_SYMBOLS})
+if (LIBUNWIND_EXECUTE_ONLY_CODE AND NOT LLVM_RUNTIMES_BUILD)
+ message(SEND_ERROR "LIBUNWIND_EXECUTE_ONLY_CODE is only supported "
+ "for runtimes build of libunwind.")
+endif()
+
# If toolchain is FPXX, we switch to FP64 to save the full FPRs. See:
# https://web.archive.org/web/20180828210612/https://dmz-portal.mips.com/wiki/MIPS_O32_ABI_-_FR0_and_FR1_Interlinking
check_symbol_exists(__mips_hard_float "" __MIPSHF)
@@ -330,6 +336,18 @@ if (C_SUPPORTS_COMMENT_LIB_PRAGMA)
endif()
endif()
+if (LIBUNWIND_EXECUTE_ONLY_CODE)
+ add_compile_flags_if_supported(-mexecute-only)
+ if (NOT CXX_SUPPORTS_MEXECUTE_ONLY_FLAG)
+ add_compile_flags_if_supported(-mpure-code)
+ if (NOT CXX_SUPPORTS_MPURE_CODE_FLAG)
+ message(SEND_ERROR
+ "Compiler doesn't support -mexecute-only or -mpure-code option!")
+ endif()
+ endif()
+ add_compile_definitions(_LIBUNWIND_EXECUTE_ONLY_CODE)
+endif()
+
#===============================================================================
# Setup Source Code
#===============================================================================
diff --git a/libunwind/src/UnwindRegistersRestore.S b/libunwind/src/UnwindRegistersRestore.S
index 5e199188945df..2a0e81a9794eb 100644
--- a/libunwind/src/UnwindRegistersRestore.S
+++ b/libunwind/src/UnwindRegistersRestore.S
@@ -16,6 +16,8 @@
#if defined(_AIX)
.toc
+#elif defined(__aarch64__) && defined(__ELF__) && defined(_LIBUNWIND_EXECUTE_ONLY_CODE)
+ .section .text,"axy",@progbits,unique,0
#else
.text
#endif
diff --git a/libunwind/src/UnwindRegistersSave.S b/libunwind/src/UnwindRegistersSave.S
index 5139a551ad245..1ff14cf272b61 100644
--- a/libunwind/src/UnwindRegistersSave.S
+++ b/libunwind/src/UnwindRegistersSave.S
@@ -16,6 +16,8 @@
#if defined(_AIX)
.toc
+#elif defined(__aarch64__) && defined(__ELF__) && defined(_LIBUNWIND_EXECUTE_ONLY_CODE)
+ .section .text,"axy",@progbits,unique,0
#else
.text
#endif
|
I simplified the configuration based on the discussion in the RFC. C and C++ compiler flags will be handled by the change in #143698. |
For a full toolchain supporting execute-only code generation the runtime libraries also need to be pre-compiled with it enabled. The generic
LLVM_EXECUTE_ONLY_CODE
CMake option can now be used during build configuration to enable execute-only code generation in libunwind.Related RFC: https://discourse.llvm.org/t/rfc-execute-only-code-support-for-runtime-libraries-on-aarch64/86180