From c850b16946a1462cc361e9713873a007e229f702 Mon Sep 17 00:00:00 2001 From: David Nguyen <87228593+davidnguyen-tech@users.noreply.github.com> Date: Fri, 20 Feb 2026 21:32:17 +0100 Subject: [PATCH 1/2] Compress debug sections with -gz=zlib for Android builds Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- eng/native/configurecompiler.cmake | 3 +++ 1 file changed, 3 insertions(+) diff --git a/eng/native/configurecompiler.cmake b/eng/native/configurecompiler.cmake index 6b9ac068fd87c6..f0e4550a5dc70a 100644 --- a/eng/native/configurecompiler.cmake +++ b/eng/native/configurecompiler.cmake @@ -44,6 +44,9 @@ if (CLR_CMAKE_HOST_UNIX) if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compile_options(-Wno-null-conversion) add_compile_options(-glldb) + if (CLR_CMAKE_TARGET_ANDROID) + add_compile_options(-gz=zlib) + endif() else() add_compile_options(-g) endif() From 847ec9d7aead50114313e4de975754d55f9c582a Mon Sep 17 00:00:00 2001 From: David Nguyen <87228593+davidnguyen-tech@users.noreply.github.com> Date: Fri, 20 Feb 2026 21:33:02 +0100 Subject: [PATCH 2/2] Strip debug symbols from static libraries at install time on Android At install time, use llvm-objcopy to extract debug symbols into a .dbg file and strip the static library. The .dbg is installed alongside the .a for automatic inclusion in the symbols NuGet package. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- eng/native/functions.cmake | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/eng/native/functions.cmake b/eng/native/functions.cmake index d35d0760dce3ce..c5257e3cd202e1 100644 --- a/eng/native/functions.cmake +++ b/eng/native/functions.cmake @@ -551,6 +551,16 @@ function(install_clr) get_symbol_file_name(${targetName} symbolFile) endif() + # For static libraries on Android, strip debug info at install time and save + # the debug symbols as a separate .dbg file for the symbols package. + set(staticLibSymbolFile "") + if (NOT CLR_CMAKE_KEEP_NATIVE_SYMBOLS + AND "${targetType}" STREQUAL "STATIC_LIBRARY" + AND CMAKE_OBJCOPY + AND CLR_CMAKE_TARGET_ANDROID) + set(staticLibSymbolFile "$.dbg") + endif() + if (${INSTALL_CLR_OPTIONAL}) set(INSTALL_CLR_OPTIONAL "OPTIONAL") else() @@ -577,10 +587,25 @@ function(install_clr) else() # We don't need to install the export libraries for our DLLs # since they won't be directly linked against. + if (NOT "${staticLibSymbolFile}" STREQUAL "") + # For static libraries: save unstripped copy as .dbg, then strip and install + install(CODE + " + set(source_file \"$\") + set(symbol_file \"${staticLibSymbolFile}\") + message(STATUS \"Stripping debug symbols from $ into $.dbg\") + execute_process(COMMAND ${CMAKE_OBJCOPY} --only-keep-debug \${source_file} \${symbol_file}) + execute_process(COMMAND ${CMAKE_OBJCOPY} --strip-debug \${source_file}) + " + COMPONENT ${INSTALL_CLR_COMPONENT} ${INSTALL_CLR_OPTIONAL}) + endif() install(PROGRAMS $ DESTINATION ${destination} COMPONENT ${INSTALL_CLR_COMPONENT} ${INSTALL_CLR_OPTIONAL}) if (NOT "${symbolFile}" STREQUAL "") install_symbol_file(${symbolFile} ${destination} COMPONENT ${INSTALL_CLR_COMPONENT} ${INSTALL_CLR_OPTIONAL}) endif() + if (NOT "${staticLibSymbolFile}" STREQUAL "") + install_symbol_file(${staticLibSymbolFile} ${destination} COMPONENT ${INSTALL_CLR_COMPONENT} ${INSTALL_CLR_OPTIONAL}) + endif() endif() if(CLR_CMAKE_PGO_INSTRUMENT)