Skip to content

Commit 4a5c345

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 6e0c2bc commit 4a5c345

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
@@ -214,6 +214,20 @@ endif()
214214
option(LLVM_INCLUDE_TESTS "Generate build targets for the runtimes unit tests." ON)
215215
option(LLVM_INCLUDE_DOCS "Generate build targets for the runtimes documentation." ON)
216216
option(LLVM_ENABLE_SPHINX "Use Sphinx to generate the runtimes documentation." OFF)
217+
option(LLVM_EXECUTE_ONLY_CODE "Compile runtime libraries as execute-only." OFF)
218+
219+
if (LLVM_EXECUTE_ONLY_CODE)
220+
# If a target doesn't support or recognise -mexecute-only, Clang will simply ignore the flag.
221+
# We can check for this case using -Werror=unused-command-line-argument.
222+
check_c_compiler_flag("-mexecute-only -Werror=unused-command-line-argument" C_SUPPORTS_MEXECUTE_ONLY)
223+
if (NOT C_SUPPORTS_MEXECUTE_ONLY)
224+
message(FATAL_ERROR "LLVM_EXECUTE_ONLY_CODE was turned on, but the target '${LLVM_TARGET_TRIPLE}'"
225+
" doesn't support the -mexecute-only flag")
226+
endif()
227+
228+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mexecute-only")
229+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mexecute-only")
230+
endif()
217231

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

0 commit comments

Comments
 (0)