Skip to content

[WIP] Privatize NativeAOT libunwind symbols#128927

Open
sbomer wants to merge 1 commit into
dotnet:mainfrom
sbomer:libunwind-localize
Open

[WIP] Privatize NativeAOT libunwind symbols#128927
sbomer wants to merge 1 commit into
dotnet:mainfrom
sbomer:libunwind-localize

Conversation

@sbomer
Copy link
Copy Markdown
Member

@sbomer sbomer commented Jun 3, 2026

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.

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>
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib
See info in area-owners.md if you want to be subscribed.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.o via relocatable link (ld -r) and run objcopy --localize-symbols=... to hide its symbols.
  • Wire this private object into both Runtime.WorkstationGC and Runtime.ServerGC on 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")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

[NAOT][android] Application linking breaks with NDK r29 because of duplicated libunwind symbols

2 participants