Skip to content

[libunwind] Add CMake option to enable execute-only code generation on AArch64 #140554

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions libunwind/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,10 @@ if (C_SUPPORTS_COMMENT_LIB_PRAGMA)
endif()
endif()

if (RUNTIMES_EXECUTE_ONLY_CODE)
add_compile_definitions(_LIBUNWIND_EXECUTE_ONLY_CODE)
endif()

#===============================================================================
# Setup Source Code
#===============================================================================
Expand Down
2 changes: 2 additions & 0 deletions libunwind/src/UnwindRegistersRestore.S
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

#if defined(_AIX)
.toc
#elif defined(__aarch64__) && defined(__ELF__) && defined(_LIBUNWIND_EXECUTE_ONLY_CODE)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defined(__ELF__) seems unnecessary. Perhaps LIBUNWIND_EXECUTE_ONLY_CODE could have a check to reject non-ELF platforms

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.section .text,"axy",@progbits,unique,0 is an ELF-specific directive, so I think it makes sense to check for an ELF target here, rather than in the CMake script.

I found a few examples in libc++ that do a similar thing, e.g. _LIBCPP_LINK_PTHREAD_LIB which is always checked as defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB). I also didn't find any checks for the target format in CMake files, so I think my approach here is reasonable.

Also, from a maintainability perspective, if a different target is ever added with execute-only code support, only the assembly files need to be updated, and the definition of _LIBUNWIND_EXECUTE_ONLY_CODE doesn't need to be touched.

.section .text,"axy",@progbits,unique,0
#else
.text
#endif
Expand Down
2 changes: 2 additions & 0 deletions libunwind/src/UnwindRegistersSave.S
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading