aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCsanád Hajdú <csanad.hajdu@arm.com>2025-11-07 09:36:00 +0100
committerGitHub <noreply@github.com>2025-11-07 09:36:00 +0100
commit927092b262e58a7f3d79fea615daecc60e61bdcb (patch)
treec32ad30d9ed6221120fc06bd464c88f94c2d35fe
parentbac427a0f634bb2f34022efe3f20e7a3a8f1d369 (diff)
downloadllvm-927092b262e58a7f3d79fea615daecc60e61bdcb.zip
llvm-927092b262e58a7f3d79fea615daecc60e61bdcb.tar.gz
llvm-927092b262e58a7f3d79fea615daecc60e61bdcb.tar.bz2
[Runtimes][CMake] Add CMake option to enable execute-only code generation on AArch64 (#143698)
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 `RUNTIMES_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.
-rw-r--r--runtimes/CMakeLists.txt14
1 files changed, 14 insertions, 0 deletions
diff --git a/runtimes/CMakeLists.txt b/runtimes/CMakeLists.txt
index d3280a5..cc756da 100644
--- a/runtimes/CMakeLists.txt
+++ b/runtimes/CMakeLists.txt
@@ -233,6 +233,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(RUNTIMES_EXECUTE_ONLY_CODE "Compile runtime libraries as execute-only." OFF)
+
+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 "RUNTIMES_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)