Skip to content

Commit 1858fd5

Browse files
committed
[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.
1 parent 97d4e96 commit 1858fd5

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

runtimes/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,20 @@ endif()
233233
option(LLVM_INCLUDE_TESTS "Generate build targets for the runtimes unit tests." ON)
234234
option(LLVM_INCLUDE_DOCS "Generate build targets for the runtimes documentation." ON)
235235
option(LLVM_ENABLE_SPHINX "Use Sphinx to generate the runtimes documentation." OFF)
236+
option(LLVM_EXECUTE_ONLY_CODE "Compile runtime libraries as execute-only." OFF)
237+
238+
if (LLVM_EXECUTE_ONLY_CODE)
239+
# If a target doesn't support or recognise -mexecute-only, Clang will simply ignore the flag.
240+
# We can check for this case using -Werror=unused-command-line-argument.
241+
check_c_compiler_flag("-mexecute-only -Werror=unused-command-line-argument" C_SUPPORTS_MEXECUTE_ONLY)
242+
if (NOT C_SUPPORTS_MEXECUTE_ONLY)
243+
message(FATAL_ERROR "LLVM_EXECUTE_ONLY_CODE was turned on, but the target '${LLVM_TARGET_TRIPLE}'"
244+
" doesn't support the -mexecute-only flag")
245+
endif()
246+
247+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mexecute-only")
248+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mexecute-only")
249+
endif()
236250

237251
# Use libtool instead of ar if you are both on an Apple host, and targeting Apple.
238252
if(CMAKE_HOST_APPLE AND APPLE)

0 commit comments

Comments
 (0)