Skip to content

Commit 63fa6eb

Browse files
committed
[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
1 parent bca39f4 commit 63fa6eb

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

libcxx/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,8 @@ endif()
318318
option(LIBCXX_HERMETIC_STATIC_LIBRARY
319319
"Do not export any symbols from the static library." ${LIBCXX_HERMETIC_STATIC_LIBRARY_DEFAULT})
320320

321+
option(LIBCXX_EXECUTE_ONLY_CODE "Compile libc++ as execute-only." OFF)
322+
321323
#===============================================================================
322324
# Check option configurations
323325
#===============================================================================
@@ -538,6 +540,17 @@ function(cxx_add_basic_build_flags target)
538540
# errors.
539541
target_compile_definitions(${target} PRIVATE -D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES)
540542

543+
if (LIBCXX_EXECUTE_ONLY_CODE)
544+
target_add_compile_flags_if_supported(${target} PRIVATE -mexecute-only)
545+
if (NOT CXX_SUPPORTS_MEXECUTE_ONLY_FLAG)
546+
target_add_compile_flags_if_supported(${target} PRIVATE -mpure-code)
547+
if (NOT CXX_SUPPORTS_MPURE_CODE_FLAG)
548+
message(SEND_ERROR "Compiler doesn't support -mexecute-only or "
549+
"-mpure-code option for target ${target}!")
550+
endif()
551+
endif()
552+
endif()
553+
541554
if (C_SUPPORTS_COMMENT_LIB_PRAGMA)
542555
if (LIBCXX_HAS_PTHREAD_LIB)
543556
target_compile_definitions(${target} PRIVATE -D_LIBCPP_LINK_PTHREAD_LIB)

0 commit comments

Comments
 (0)