Skip to content

[libc++abi] Add CMake option to enable execute-only code generation on AArch64 #140553

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

Closed
wants to merge 1 commit into from

Conversation

Il-Capitano
Copy link
Contributor

For a full toolchain supporting execute-only code generation the runtime libraries also need to be pre-compiled with it enabled. For libc++abi this can now be enabled with the LIBCXXABI_EXECUTE_ONLY_CODE CMake option during build configuration.

Related RFC: https://discourse.llvm.org/t/rfc-execute-only-code-support-for-runtime-libraries-on-aarch64/86180

…n AArch64

For a full toolchain supporting execute-only code generation the runtime
libraries also need to be pre-compiled with it enabled. For libc++abi
this can now be enabled with the `LIBCXXABI_EXECUTE_ONLY_CODE` CMake
option during build configuration.

Related RFC: https://discourse.llvm.org/t/rfc-execute-only-code-support-for-runtime-libraries-on-aarch64/86180
@Il-Capitano Il-Capitano requested a review from a team as a code owner May 19, 2025 14:56
@llvmbot llvmbot added the libc++abi libc++abi C++ Runtime Library. Not libc++. label May 19, 2025
@llvmbot
Copy link
Member

llvmbot commented May 19, 2025

@llvm/pr-subscribers-libcxxabi

Author: Csanád Hajdú (Il-Capitano)

Changes

For a full toolchain supporting execute-only code generation the runtime libraries also need to be pre-compiled with it enabled. For libc++abi this can now be enabled with the LIBCXXABI_EXECUTE_ONLY_CODE CMake option during build configuration.

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/140553.diff

1 Files Affected:

  • (modified) libcxxabi/CMakeLists.txt (+13)
diff --git a/libcxxabi/CMakeLists.txt b/libcxxabi/CMakeLists.txt
index 3e2f80b818450..d2e1b821c1674 100644
--- a/libcxxabi/CMakeLists.txt
+++ b/libcxxabi/CMakeLists.txt
@@ -143,6 +143,8 @@ endif()
 option(LIBCXXABI_HERMETIC_STATIC_LIBRARY
   "Do not export any symbols from the static library." ${LIBCXXABI_HERMETIC_STATIC_LIBRARY_DEFAULT})
 
+option(LIBCXXABI_EXECUTE_ONLY_CODE "Compile libc++abi as execute-only." OFF)
+
 if(MINGW)
   set(LIBCXXABI_DEFAULT_TEST_CONFIG "llvm-libc++abi-mingw.cfg.in")
 elseif(WIN32) # clang-cl
@@ -446,6 +448,17 @@ if (C_SUPPORTS_COMMENT_LIB_PRAGMA)
   endif()
 endif()
 
+if (LIBCXXABI_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()
+endif()
+
 string(REPLACE ";" " " LIBCXXABI_CXX_FLAGS "${LIBCXXABI_CXX_FLAGS}")
 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LIBCXXABI_CXX_FLAGS}")
 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBCXXABI_C_FLAGS}")

@Il-Capitano
Copy link
Contributor Author

Closing in favour of #143698.

@Il-Capitano Il-Capitano deleted the xom-libcxxabi branch June 11, 2025 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++abi libc++abi C++ Runtime Library. Not libc++.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants