Skip to content

Commit 0bb4c24

Browse files
authored
Merge pull request #229 from winnerspiros/copilot/fix-crash-issues
Make Android startup crashes diagnosable: keep native symbols + in-process crash dumper to user-accessible file
2 parents f9787ec + 46cb618 commit 0bb4c24

5 files changed

Lines changed: 514 additions & 2 deletions

File tree

osu.Android/Native/CMakeLists.txt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,20 @@ set(CMAKE_C_FLAGS_RELEASE "-O3 -flto=thin -ffast-math -ffunction-sections -fda
1616
# -Wl,-z,max-page-size=16384: align ELF LOAD segments to 16 KB for Android 15+
1717
# devices with 16 KB page sizes. Without this, the .so will fail to load on
1818
# such devices. NDK r28+ supports this flag.
19-
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "-Wl,--gc-sections -Wl,-z,max-page-size=16384 -s")
19+
#
20+
# IMPORTANT: do NOT pass `-s` (or `-Wl,-s`) here. Stripping the native library
21+
# removes the symbol table, which means Android tombstones — and crash-report
22+
# tools like Crash Log Viewer that read them — print only `pc=<hex>` with no
23+
# function name. That makes the SDLThread / audio-thread SIGSEGVs we have been
24+
# chasing essentially unfixable from a tombstone alone, because we cannot tell
25+
# whether the null indirect call originated in our `OboeBridge::onAudioReady`,
26+
# in Oboe itself, in libvulkan, or in the renderer. Keeping symbols costs only
27+
# a few hundred KB in the on-device .so (and zero APK download size when LZ4
28+
# assembly compression is on, since the .so is also compressed), and it is the
29+
# single highest-leverage change we can make for diagnosing real-device crashes.
30+
# `-Wl,--gc-sections` still removes unreferenced sections; only the symbol
31+
# *names* are retained.
32+
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "-Wl,--gc-sections -Wl,-z,max-page-size=16384")
2033

2134
# Disable Oboe's flowgraph module — we don't use any audio processing/conversion
2235
# features (our bridge outputs silence for latency measurement only).
@@ -64,10 +77,15 @@ set(OBOE_LIB oboe)
6477
find_library(vulkan-lib vulkan REQUIRED)
6578
find_library(log-lib log REQUIRED)
6679
find_library(android-lib android REQUIRED)
80+
# `dl` is needed for dladdr() in crash_handler.cpp (symbol resolution from PCs).
81+
# It is normally auto-linked on Android, but make the dependency explicit so we
82+
# don't accidentally lose dladdr if the toolchain default ever changes.
83+
find_library(dl-lib dl REQUIRED)
6784

6885
add_library(osu_native SHARED
6986
oboe_bridge.cpp
7087
vulkan_bridge.cpp
88+
crash_handler.cpp
7189
)
7290

7391

@@ -76,4 +94,5 @@ target_link_libraries(osu_native
7694
${vulkan-lib}
7795
${log-lib}
7896
${android-lib}
97+
${dl-lib}
7998
)

osu.Android/Native/OboeAudioBridge.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,5 +215,6 @@ public void Dispose()
215215
[DllImport(lib_name)] internal static extern void nADPFReportActualDuration(IntPtr sessionPtr, long actualDurationNanos);
216216
[DllImport(lib_name)] internal static extern void nADPFUpdateTargetDuration(IntPtr sessionPtr, long targetDurationNanos);
217217
[DllImport(lib_name)] internal static extern void nADPFCloseSession(IntPtr sessionPtr);
218+
[DllImport(lib_name)] internal static extern void nInstallCrashHandler([MarshalAs(UnmanagedType.LPUTF8Str)] string? logPath);
218219
}
219220
}

0 commit comments

Comments
 (0)