From 4a5c345032674093b5340f136cf5ce741c796f64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Csan=C3=A1d=20Hajd=C3=BA?= Date: Wed, 11 Jun 2025 11:18:00 +0200 Subject: [PATCH 1/2] [Runtimes][CMake] Add CMake option to enable execute-only code generation on AArch64 Based on the discussion in https://discourse.llvm.org/t/rfc-execute-only-code-support-for-runtime-libraries-on-aarch64/86180 a single, global configuration option should be used to enable execute-only code generation for the runtime libraries. The new option `LLVM_EXECUTE_ONLY_CODE` adds the `-mexecute-only` flag to `CMAKE_C_FLAGS` and `CMAKE_CXX_FLAGS`, which simplifies the library-level configuration needed for the runtime libraries. Project-specific changes are still needed to handle assembly sources, e.g. in compiler-rt and libunwind. --- runtimes/CMakeLists.txt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/runtimes/CMakeLists.txt b/runtimes/CMakeLists.txt index 878b2eee38618..b1dc0b5b4a1d0 100644 --- a/runtimes/CMakeLists.txt +++ b/runtimes/CMakeLists.txt @@ -214,6 +214,20 @@ endif() option(LLVM_INCLUDE_TESTS "Generate build targets for the runtimes unit tests." ON) option(LLVM_INCLUDE_DOCS "Generate build targets for the runtimes documentation." ON) option(LLVM_ENABLE_SPHINX "Use Sphinx to generate the runtimes documentation." OFF) +option(LLVM_EXECUTE_ONLY_CODE "Compile runtime libraries as execute-only." OFF) + +if (LLVM_EXECUTE_ONLY_CODE) + # If a target doesn't support or recognise -mexecute-only, Clang will simply ignore the flag. + # We can check for this case using -Werror=unused-command-line-argument. + check_c_compiler_flag("-mexecute-only -Werror=unused-command-line-argument" C_SUPPORTS_MEXECUTE_ONLY) + if (NOT C_SUPPORTS_MEXECUTE_ONLY) + message(FATAL_ERROR "LLVM_EXECUTE_ONLY_CODE was turned on, but the target '${LLVM_TARGET_TRIPLE}'" + " doesn't support the -mexecute-only flag") + endif() + + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mexecute-only") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mexecute-only") +endif() # Use libtool instead of ar if you are both on an Apple host, and targeting Apple. if(CMAKE_HOST_APPLE AND APPLE) From 76448be76d276b46cab12714b3f3f99110ad7f0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Csan=C3=A1d=20Hajd=C3=BA?= Date: Thu, 26 Jun 2025 14:28:00 +0200 Subject: [PATCH 2/2] Rename LLVM_EXECUTE_ONLY_CODE to RUNTIMES_EXECUTE_ONLY_CODE --- runtimes/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/runtimes/CMakeLists.txt b/runtimes/CMakeLists.txt index b1dc0b5b4a1d0..724bd86ced647 100644 --- a/runtimes/CMakeLists.txt +++ b/runtimes/CMakeLists.txt @@ -214,14 +214,14 @@ endif() option(LLVM_INCLUDE_TESTS "Generate build targets for the runtimes unit tests." ON) option(LLVM_INCLUDE_DOCS "Generate build targets for the runtimes documentation." ON) option(LLVM_ENABLE_SPHINX "Use Sphinx to generate the runtimes documentation." OFF) -option(LLVM_EXECUTE_ONLY_CODE "Compile runtime libraries as execute-only." OFF) +option(RUNTIMES_EXECUTE_ONLY_CODE "Compile runtime libraries as execute-only." OFF) -if (LLVM_EXECUTE_ONLY_CODE) +if (RUNTIMES_EXECUTE_ONLY_CODE) # If a target doesn't support or recognise -mexecute-only, Clang will simply ignore the flag. # We can check for this case using -Werror=unused-command-line-argument. check_c_compiler_flag("-mexecute-only -Werror=unused-command-line-argument" C_SUPPORTS_MEXECUTE_ONLY) if (NOT C_SUPPORTS_MEXECUTE_ONLY) - message(FATAL_ERROR "LLVM_EXECUTE_ONLY_CODE was turned on, but the target '${LLVM_TARGET_TRIPLE}'" + message(FATAL_ERROR "RUNTIMES_EXECUTE_ONLY_CODE was turned on, but the target '${LLVM_TARGET_TRIPLE}'" " doesn't support the -mexecute-only flag") endif()