From 63fa6eb472e830ed70e80456fe2fd4b69082811b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Csan=C3=A1d=20Hajd=C3=BA?= Date: Mon, 19 May 2025 12:07:05 +0200 Subject: [PATCH] [libc++] 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++ this can now be enabled with the `LIBCXX_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 --- libcxx/CMakeLists.txt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt index dffdd7a3c70a6..a3e0d3e909255 100644 --- a/libcxx/CMakeLists.txt +++ b/libcxx/CMakeLists.txt @@ -318,6 +318,8 @@ endif() option(LIBCXX_HERMETIC_STATIC_LIBRARY "Do not export any symbols from the static library." ${LIBCXX_HERMETIC_STATIC_LIBRARY_DEFAULT}) +option(LIBCXX_EXECUTE_ONLY_CODE "Compile libc++ as execute-only." OFF) + #=============================================================================== # Check option configurations #=============================================================================== @@ -538,6 +540,17 @@ function(cxx_add_basic_build_flags target) # errors. target_compile_definitions(${target} PRIVATE -D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) + if (LIBCXX_EXECUTE_ONLY_CODE) + target_add_compile_flags_if_supported(${target} PRIVATE -mexecute-only) + if (NOT CXX_SUPPORTS_MEXECUTE_ONLY_FLAG) + target_add_compile_flags_if_supported(${target} PRIVATE -mpure-code) + if (NOT CXX_SUPPORTS_MPURE_CODE_FLAG) + message(SEND_ERROR "Compiler doesn't support -mexecute-only or " + "-mpure-code option for target ${target}!") + endif() + endif() + endif() + if (C_SUPPORTS_COMMENT_LIB_PRAGMA) if (LIBCXX_HAS_PTHREAD_LIB) target_compile_definitions(${target} PRIVATE -D_LIBCPP_LINK_PTHREAD_LIB)