Skip to content

Commit c69f17e

Browse files
committed
[libunwind] 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 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
1 parent bca39f4 commit c69f17e

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

libunwind/CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ option(LIBUNWIND_USE_FRAME_HEADER_CACHE "Cache frame headers for unwinding. Requ
5555
option(LIBUNWIND_REMEMBER_HEAP_ALLOC "Use heap instead of the stack for .cfi_remember_state." OFF)
5656
option(LIBUNWIND_INSTALL_HEADERS "Install the libunwind headers." ON)
5757
option(LIBUNWIND_ENABLE_FRAME_APIS "Include libgcc-compatible frame apis." OFF)
58+
option(LIBUNWIND_EXECUTE_ONLY_CODE "Compile libunwind as execute-only." OFF)
5859

5960
set(LIBUNWIND_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
6061
"Define suffix of library directory name (32/64)")
@@ -109,6 +110,11 @@ endif()
109110
option(LIBUNWIND_HIDE_SYMBOLS
110111
"Do not export any symbols from the static library." ${LIBUNWIND_DEFAULT_HIDE_SYMBOLS})
111112

113+
if (LIBUNWIND_EXECUTE_ONLY_CODE AND NOT LLVM_RUNTIMES_BUILD)
114+
message(SEND_ERROR "LIBUNWIND_EXECUTE_ONLY_CODE is only supported "
115+
"for runtimes build of libunwind.")
116+
endif()
117+
112118
# If toolchain is FPXX, we switch to FP64 to save the full FPRs. See:
113119
# https://web.archive.org/web/20180828210612/https://dmz-portal.mips.com/wiki/MIPS_O32_ABI_-_FR0_and_FR1_Interlinking
114120
check_symbol_exists(__mips_hard_float "" __MIPSHF)
@@ -330,6 +336,18 @@ if (C_SUPPORTS_COMMENT_LIB_PRAGMA)
330336
endif()
331337
endif()
332338

339+
if (LIBUNWIND_EXECUTE_ONLY_CODE)
340+
add_compile_flags_if_supported(-mexecute-only)
341+
if (NOT CXX_SUPPORTS_MEXECUTE_ONLY_FLAG)
342+
add_compile_flags_if_supported(-mpure-code)
343+
if (NOT CXX_SUPPORTS_MPURE_CODE_FLAG)
344+
message(SEND_ERROR
345+
"Compiler doesn't support -mexecute-only or -mpure-code option!")
346+
endif()
347+
endif()
348+
add_compile_definitions(_LIBUNWIND_EXECUTE_ONLY_CODE)
349+
endif()
350+
333351
#===============================================================================
334352
# Setup Source Code
335353
#===============================================================================

libunwind/src/UnwindRegistersRestore.S

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#if defined(_AIX)
1818
.toc
19+
#elif defined(__aarch64__) && defined(__ELF__) && defined(_LIBUNWIND_EXECUTE_ONLY_CODE)
20+
.section .text,"axy",@progbits,unique,0
1921
#else
2022
.text
2123
#endif

libunwind/src/UnwindRegistersSave.S

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#if defined(_AIX)
1818
.toc
19+
#elif defined(__aarch64__) && defined(__ELF__) && defined(_LIBUNWIND_EXECUTE_ONLY_CODE)
20+
.section .text,"axy",@progbits,unique,0
1921
#else
2022
.text
2123
#endif

0 commit comments

Comments
 (0)