[libcxx-commits] [libcxxabi] [libc++abi] Add CMake option to enable execute-only code generation on AArch64 (PR #140553)

Csanád Hajdú via libcxx-commits libcxx-commits at lists.llvm.org
Mon May 19 07:56:27 PDT 2025


https://github.com/Il-Capitano created https://github.com/llvm/llvm-project/pull/140553

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

>From 7c5d033d9336fd0630bcb8923a3db82b0dfb7aad Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Csan=C3=A1d=20Hajd=C3=BA?= <csanad.hajdu at arm.com>
Date: Mon, 19 May 2025 12:12:08 +0200
Subject: [PATCH] [libc++abi] 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 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
---
 libcxxabi/CMakeLists.txt | 13 +++++++++++++
 1 file changed, 13 insertions(+)

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}")



More information about the libcxx-commits mailing list