https://github.com/Il-Capitano updated https://github.com/llvm/llvm-project/pull/140554
From 8f33cec6f525b5f81a4e7e7fdda8165e5a40f04f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Csan=C3=A1d=20Hajd=C3=BA?= <[email protected]> Date: Mon, 19 May 2025 12:29:43 +0200 Subject: [PATCH 1/3] [libunwind] Add CMake option to enable execute-only code generation on 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 --- libunwind/CMakeLists.txt | 18 ++++++++++++++++++ libunwind/src/UnwindRegistersRestore.S | 2 ++ libunwind/src/UnwindRegistersSave.S | 2 ++ 3 files changed, 22 insertions(+) diff --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt index 5f4b0902d522c..e2461400f7840 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) @@ -332,6 +338,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 198735fa800a9..fd306ed8c5230 100644 --- a/libunwind/src/UnwindRegistersRestore.S +++ b/libunwind/src/UnwindRegistersRestore.S @@ -18,6 +18,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 619a59751151e..b7ddd0a621d18 100644 --- a/libunwind/src/UnwindRegistersSave.S +++ b/libunwind/src/UnwindRegistersSave.S @@ -18,6 +18,8 @@ #if defined(_AIX) .toc +#elif defined(__aarch64__) && defined(__ELF__) && defined(_LIBUNWIND_EXECUTE_ONLY_CODE) + .section .text,"axy",@progbits,unique,0 #else .text #endif From f3fdfa60bdc65bcc93b139e82d62823982cbd446 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Csan=C3=A1d=20Hajd=C3=BA?= <[email protected]> Date: Wed, 11 Jun 2025 11:13:11 +0200 Subject: [PATCH 2/3] Simplify CMake configuration based on RFC feedback --- libunwind/CMakeLists.txt | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt index e2461400f7840..e6e9411489b91 100644 --- a/libunwind/CMakeLists.txt +++ b/libunwind/CMakeLists.txt @@ -55,7 +55,6 @@ 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)") @@ -110,11 +109,6 @@ 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) @@ -338,15 +332,7 @@ 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() +if (LLVM_EXECUTE_ONLY_CODE) add_compile_definitions(_LIBUNWIND_EXECUTE_ONLY_CODE) endif() From 37f0857f7300f8e4719fd44eb50a974c463e4c5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Csan=C3=A1d=20Hajd=C3=BA?= <[email protected]> Date: Thu, 26 Jun 2025 14:29:05 +0200 Subject: [PATCH 3/3] Rename LLVM_EXECUTE_ONLY_CODE to RUNTIMES_EXECUTE_ONLY_CODE --- libunwind/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt index e6e9411489b91..97edff0b87ea3 100644 --- a/libunwind/CMakeLists.txt +++ b/libunwind/CMakeLists.txt @@ -332,7 +332,7 @@ if (C_SUPPORTS_COMMENT_LIB_PRAGMA) endif() endif() -if (LLVM_EXECUTE_ONLY_CODE) +if (RUNTIMES_EXECUTE_ONLY_CODE) add_compile_definitions(_LIBUNWIND_EXECUTE_ONLY_CODE) endif() _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
