[WIP] Privatize NativeAOT libunwind symbols#128927
Open
sbomer wants to merge 1 commit into
Open
Conversation
Fold the NativeAOT libunwind-dependent objects into a private relocatable object and localize the libunwind-origin symbols before archiving the runtime libraries. This prevents bundled libunwind symbols from colliding with platform libunwind implementations while keeping runtime entrypoints externally visible. Assisted-by: Copilot CLI:gpt-5.5 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
|
Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the NativeAOT runtime (CoreCLR nativeaot/Runtime CMake build) to avoid libunwind symbol collisions by building the in-tree llvm-libunwind sources into a single relocatable object and then localizing (privatizing) its defined global symbols.
Changes:
- Add a CMake script to enumerate defined global symbols from the private libunwind object inputs (excluding selected runtime entrypoints).
- Build
Runtime.PrivateLibunwind.ovia relocatable link (ld -r) and runobjcopy --localize-symbols=...to hide its symbols. - Wire this private object into both
Runtime.WorkstationGCandRuntime.ServerGCon non-Apple, non-WASM Unix NativeAOT builds.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/nativeaot/Runtime/Full/GeneratePrivateLibunwindSymbols.cmake | New helper script to generate the symbol list used for localization. |
| src/coreclr/nativeaot/Runtime/Full/CMakeLists.txt | Adds the private libunwind object build (nm → ld -r → objcopy) and links it into runtime archives. |
| src/coreclr/nativeaot/Runtime/CMakeLists.txt | Introduces conditional path to move libunwind + unwinding helpers into the private object build on supported Unix targets. |
Copilot's findings
- Files reviewed: 3/3 changed files
- Comments generated: 3
Comment on lines
+30
to
+34
| set(NATIVEAOT_PRIVATE_LIBUNWIND_LINKER "${CMAKE_LINKER}") | ||
| if(NATIVEAOT_PRIVATE_LIBUNWIND_LINKER MATCHES "llvm-link(\\.exe)?$") | ||
| get_filename_component(NATIVEAOT_PRIVATE_LIBUNWIND_TOOL_DIR "${CMAKE_NM}" DIRECTORY) | ||
| set(NATIVEAOT_PRIVATE_LIBUNWIND_LINKER "${NATIVEAOT_PRIVATE_LIBUNWIND_TOOL_DIR}/ld.lld") | ||
| endif() |
| get_filename_component(NATIVEAOT_PRIVATE_LIBUNWIND_TOOL_DIR "${CMAKE_NM}" DIRECTORY) | ||
| set(NATIVEAOT_PRIVATE_LIBUNWIND_LINKER "${NATIVEAOT_PRIVATE_LIBUNWIND_TOOL_DIR}/ld.lld") | ||
| endif() | ||
|
|
Comment on lines
+46
to
+50
| # UnwindHelpers.cpp is linked into the private libunwind object because it | ||
| # instantiates libunwind templates and references libunwind assembly | ||
| # helpers. Its public runtime entrypoints must remain externally visible to | ||
| # UnixNativeCodeManager.cpp. | ||
| if(SYMBOL_NAME MATCHES "^_ZN13UnwindHelpers") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Trying another approach to fix #121172.
The previous approach used an ifdef, but this caused problems because it allowed some of the excluded symbols to be resolved from libgcc (see #128830). On further investigation I realized that the ifdef approach only worked because it prevented any global symbols being used from libunwind.cpp.o. In general we might need to resolve global symbols from our libunwind copy while also avoiding conflicts when linking in external libunwind.
This approach is an attempt to avoid that fragility by doing a relocatable link of the libunwind sources so that they get resolved early, and then localizing the symbols to make them non-global.