llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-libunwind Author: Csanád Hajdú (Il-Capitano) <details> <summary>Changes</summary> For a full toolchain supporting execute-only code generation the runtime libraries also need to be pre-compiled with it enabled. For libunwind this can now be enabled with the `LIBUNWIND_EXECUTE_ONLY_CODE` CMake option during build configuration. The build option can only be enabled for a runtimes build of libunwind, because a recent version of Clang is needed to correctly compile assembly files with execute-only code support. Related RFC: https://discourse.llvm.org/t/rfc-execute-only-code-support-for-runtime-libraries-on-aarch64/86180 --- Full diff: https://github.com/llvm/llvm-project/pull/140554.diff 3 Files Affected: - (modified) libunwind/CMakeLists.txt (+18) - (modified) libunwind/src/UnwindRegistersRestore.S (+2) - (modified) libunwind/src/UnwindRegistersSave.S (+2) ``````````diff diff --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt index e27f3c2e2fc17..75195fe022d4b 100644 --- a/libunwind/CMakeLists.txt +++ b/libunwind/CMakeLists.txt @@ -55,6 +55,7 @@ option(LIBUNWIND_USE_FRAME_HEADER_CACHE "Cache frame headers for unwinding. Requ option(LIBUNWIND_REMEMBER_HEAP_ALLOC "Use heap instead of the stack for .cfi_remember_state." OFF) option(LIBUNWIND_INSTALL_HEADERS "Install the libunwind headers." ON) option(LIBUNWIND_ENABLE_FRAME_APIS "Include libgcc-compatible frame apis." OFF) +option(LIBUNWIND_EXECUTE_ONLY_CODE "Compile libunwind as execute-only." OFF) set(LIBUNWIND_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING "Define suffix of library directory name (32/64)") @@ -109,6 +110,11 @@ endif() option(LIBUNWIND_HIDE_SYMBOLS "Do not export any symbols from the static library." ${LIBUNWIND_DEFAULT_HIDE_SYMBOLS}) +if (LIBUNWIND_EXECUTE_ONLY_CODE AND NOT LLVM_RUNTIMES_BUILD) + message(SEND_ERROR "LIBUNWIND_EXECUTE_ONLY_CODE is only supported " + "for runtimes build of libunwind.") +endif() + # If toolchain is FPXX, we switch to FP64 to save the full FPRs. See: # https://web.archive.org/web/20180828210612/https://dmz-portal.mips.com/wiki/MIPS_O32_ABI_-_FR0_and_FR1_Interlinking check_symbol_exists(__mips_hard_float "" __MIPSHF) @@ -330,6 +336,18 @@ if (C_SUPPORTS_COMMENT_LIB_PRAGMA) endif() endif() +if (LIBUNWIND_EXECUTE_ONLY_CODE) + add_compile_flags_if_supported(-mexecute-only) + if (NOT CXX_SUPPORTS_MEXECUTE_ONLY_FLAG) + add_compile_flags_if_supported(-mpure-code) + if (NOT CXX_SUPPORTS_MPURE_CODE_FLAG) + message(SEND_ERROR + "Compiler doesn't support -mexecute-only or -mpure-code option!") + endif() + endif() + add_compile_definitions(_LIBUNWIND_EXECUTE_ONLY_CODE) +endif() + #=============================================================================== # Setup Source Code #=============================================================================== diff --git a/libunwind/src/UnwindRegistersRestore.S b/libunwind/src/UnwindRegistersRestore.S index 5e199188945df..2a0e81a9794eb 100644 --- a/libunwind/src/UnwindRegistersRestore.S +++ b/libunwind/src/UnwindRegistersRestore.S @@ -16,6 +16,8 @@ #if defined(_AIX) .toc +#elif defined(__aarch64__) && defined(__ELF__) && defined(_LIBUNWIND_EXECUTE_ONLY_CODE) + .section .text,"axy",@progbits,unique,0 #else .text #endif diff --git a/libunwind/src/UnwindRegistersSave.S b/libunwind/src/UnwindRegistersSave.S index 5139a551ad245..1ff14cf272b61 100644 --- a/libunwind/src/UnwindRegistersSave.S +++ b/libunwind/src/UnwindRegistersSave.S @@ -16,6 +16,8 @@ #if defined(_AIX) .toc +#elif defined(__aarch64__) && defined(__ELF__) && defined(_LIBUNWIND_EXECUTE_ONLY_CODE) + .section .text,"axy",@progbits,unique,0 #else .text #endif `````````` </details> https://github.com/llvm/llvm-project/pull/140554 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits