Guard unused llvm-libunwind symbols to avoid duplicates on Android#128667
Conversation
|
Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib |
There was a problem hiding this comment.
Pull request overview
This PR updates the NativeAOT build of the vendored llvm-libunwind to avoid duplicate symbol conflicts (notably on Android NDK r29) by compiling out libunwind’s public unw_* entrypoints and related exception-dispatch code that NativeAOT doesn’t use, and by routing NativeAOT’s unwind-section discovery through a runtime-owned helper instead of libunwind’s LocalAddressSpace::sThisAddressSpace singleton.
Changes:
- Add
_LIBUNWIND_NATIVEAOTand use it to guard outunw_*APIs (and theLocalAddressSpace::sThisAddressSpacesingleton) inlibunwind.cpp, plus dependent EHABI exception-dispatch exports inUnwind-EHABI.cpp. - Introduce
UnwindHelpers::FindUnwindSections()and switchUnixNativeCodeManagerto use it (avoiding the now-guardedsThisAddressSpace). - Record the patch application in
llvm-libunwind-version.txtand enable the new define in the NativeAOT runtime CMake configuration.
Show a summary per file
| File | Description |
|---|---|
| src/native/external/llvm-libunwind/src/Unwind-EHABI.cpp | Guards EHABI exception-dispatch exports when _LIBUNWIND_NATIVEAOT is set to avoid references to removed __unw_* APIs. |
| src/native/external/llvm-libunwind/src/libunwind.cpp | Guards the public unw_* API surface and the LocalAddressSpace::sThisAddressSpace singleton under _LIBUNWIND_NATIVEAOT. |
| src/native/external/llvm-libunwind/src/AddressSpace.hpp | Guards the LocalAddressSpace::sThisAddressSpace static member declaration under _LIBUNWIND_NATIVEAOT. |
| src/native/external/llvm-libunwind-version.txt | Notes the applied commit associated with this local patch. |
| src/coreclr/nativeaot/Runtime/unix/UnwindHelpers.h | Declares the new UnwindHelpers::FindUnwindSections accessor. |
| src/coreclr/nativeaot/Runtime/unix/UnwindHelpers.cpp | Implements FindUnwindSections by delegating to the existing file-scope _addressSpace. |
| src/coreclr/nativeaot/Runtime/unix/UnixNativeCodeManager.cpp | Replaces use of LocalAddressSpace::sThisAddressSpace.findUnwindSections with UnwindHelpers::FindUnwindSections. |
| src/coreclr/nativeaot/Runtime/CMakeLists.txt | Defines _LIBUNWIND_NATIVEAOT=1 for Unix NativeAOT builds to enable the guarding behavior. |
Copilot's findings
- Files reviewed: 8/8 changed files
- Comments generated: 0
|
If it's a negative |
Deleting the code creates more conflicts during updates. We won't be able to upstream the deletion either. I think ifdefing is better. |
NativeAOT uses llvm-libunwind's internal C++ classes directly (DwarfInstructions, CompactUnwinder, UnwindCursor, LocalAddressSpace) and does not call the public unw_* C API. These symbols conflict with platform libunwind on Android NDK r29. Add a _LIBUNWIND_NATIVEAOT define that guards out the public API symbols NativeAOT does not use: - libunwind.cpp: wrap the entire file (except debug logging) in #if !defined(_LIBUNWIND_NATIVEAOT) as a purely additive patch, making it resilient to upstream llvm-libunwind updates - Unwind-EHABI.cpp: the C++ exception dispatch functions are also guarded because they depend on the now-guarded unw_* functions and would cause undefined symbol errors on ARM32 Switch UnixNativeCodeManager to use a new UnwindHelpers::FindUnwindSections() accessor instead of the now-guarded sThisAddressSpace singleton. This delegates to the existing file-local LocalAddressSpace instance in UnwindHelpers.cpp. Co-authored-by: Jan Kotas <jkotas@microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Reference fde4a5b (Guard unused llvm-libunwind symbols). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
@jkotas can you please help merge this without squashing? |
NativeAOT uses llvm-libunwind's internal C++ classes directly
(DwarfInstructions, CompactUnwinder, UnwindCursor, LocalAddressSpace)
and does not call the public unw_* C API. These symbols conflict with
platform libunwind on Android NDK r29.
Add a _LIBUNWIND_NATIVEAOT define that guards out the public API
symbols NativeAOT does not use:
the LocalAddressSpace::sThisAddressSpace singleton
guarded because they depend on the now-guarded unw_* functions
and would cause undefined symbol errors on ARM32
Switch UnixNativeCodeManager to use a new UnwindHelpers::FindUnwindSections()
accessor instead of the now-guarded sThisAddressSpace singleton. This
delegates to the existing file-local LocalAddressSpace instance in
UnwindHelpers.cpp
Fixes #121172