From 81700976429419c7297d4fe84babced3d3bb87f0 Mon Sep 17 00:00:00 2001 From: Milos Kotlar Date: Wed, 11 Feb 2026 13:25:23 +0100 Subject: [PATCH 1/8] Enable symbol stripping for Apple platforms --- src/coreclr/tools/aot/ILCompiler/ILCompiler_publish.csproj | 3 --- src/tasks/Crossgen2Tasks/Microsoft.NET.CrossGen.targets | 4 ++-- src/tests/Common/CLRTest.CrossGen.targets | 6 ++++++ src/tests/Common/XUnitLogChecker/XUnitLogChecker.csproj | 3 --- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/coreclr/tools/aot/ILCompiler/ILCompiler_publish.csproj b/src/coreclr/tools/aot/ILCompiler/ILCompiler_publish.csproj index d07363514d8914..239e3f83618a1b 100644 --- a/src/coreclr/tools/aot/ILCompiler/ILCompiler_publish.csproj +++ b/src/coreclr/tools/aot/ILCompiler/ILCompiler_publish.csproj @@ -10,9 +10,6 @@ false true true - - - false diff --git a/src/tasks/Crossgen2Tasks/Microsoft.NET.CrossGen.targets b/src/tasks/Crossgen2Tasks/Microsoft.NET.CrossGen.targets index e20b05ee033e52..ceb19f5813ac1a 100644 --- a/src/tasks/Crossgen2Tasks/Microsoft.NET.CrossGen.targets +++ b/src/tasks/Crossgen2Tasks/Microsoft.NET.CrossGen.targets @@ -603,8 +603,8 @@ Copyright (c) .NET Foundation. All rights reserved. - - + + diff --git a/src/tests/Common/CLRTest.CrossGen.targets b/src/tests/Common/CLRTest.CrossGen.targets index 8b45eb30ddec36..51bccb036fa981 100644 --- a/src/tests/Common/CLRTest.CrossGen.targets +++ b/src/tests/Common/CLRTest.CrossGen.targets @@ -156,6 +156,12 @@ if [ ! -z ${RunCrossGen2+x} ]%3B then echo clang -dynamiclib -o "$__OutputFileFinal" "$__OutputFile" -install_name "@rpath/`basename "$__OutputFileFinal"`" -Wl,-dead_strip clang -dynamiclib -o "$__OutputFileFinal" "$__OutputFile" -install_name "@rpath/`basename "$__OutputFileFinal"`" -Wl,-dead_strip __linkExitCode=$? + + if [ $__linkExitCode -eq 0 ] && [ "$(StripSymbols)" == "true" ]; then + echo "Stripping symbols from: $(basename "$__OutputFileFinal")" + dsymutil "$__OutputFileFinal" && strip -no_code_signature_warning -x "$__OutputFileFinal" + __linkExitCode=$? + fi fi echo "Running R2RDump: $__R2RDumpCommand" diff --git a/src/tests/Common/XUnitLogChecker/XUnitLogChecker.csproj b/src/tests/Common/XUnitLogChecker/XUnitLogChecker.csproj index 900df8cea49d76..5b06ca87506641 100644 --- a/src/tests/Common/XUnitLogChecker/XUnitLogChecker.csproj +++ b/src/tests/Common/XUnitLogChecker/XUnitLogChecker.csproj @@ -9,9 +9,6 @@ true true false - - - false From 5925853dd9908c596fce32b2920990d69cda3888 Mon Sep 17 00:00:00 2001 From: Milos Kotlar Date: Wed, 11 Feb 2026 13:26:01 +0100 Subject: [PATCH 2/8] Revert changes --- src/tasks/Crossgen2Tasks/Microsoft.NET.CrossGen.targets | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tasks/Crossgen2Tasks/Microsoft.NET.CrossGen.targets b/src/tasks/Crossgen2Tasks/Microsoft.NET.CrossGen.targets index ceb19f5813ac1a..e20b05ee033e52 100644 --- a/src/tasks/Crossgen2Tasks/Microsoft.NET.CrossGen.targets +++ b/src/tasks/Crossgen2Tasks/Microsoft.NET.CrossGen.targets @@ -603,8 +603,8 @@ Copyright (c) .NET Foundation. All rights reserved. - - + + From 2145b8ce5cf653cb0d1c24d1e12f597aa89cdf92 Mon Sep 17 00:00:00 2001 From: Milos Kotlar Date: Wed, 11 Feb 2026 13:26:48 +0100 Subject: [PATCH 3/8] Enable stripping in crossgen2_publish --- src/coreclr/tools/aot/crossgen2/crossgen2_publish.csproj | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/coreclr/tools/aot/crossgen2/crossgen2_publish.csproj b/src/coreclr/tools/aot/crossgen2/crossgen2_publish.csproj index ef721045174a58..f5f2fe11f65886 100644 --- a/src/coreclr/tools/aot/crossgen2/crossgen2_publish.csproj +++ b/src/coreclr/tools/aot/crossgen2/crossgen2_publish.csproj @@ -10,9 +10,6 @@ false true true - - - false From 0424d5ecac8dbeb36c1ea4054a0bcc521e2983ce Mon Sep 17 00:00:00 2001 From: Milos Kotlar Date: Thu, 12 Mar 2026 14:05:04 +0100 Subject: [PATCH 4/8] Enable debug information generation for Apple targets by adding -gline-tables-only compile option in CMakeLists.txt --- src/native/libs/System.Native/CMakeLists.txt | 4 ++++ .../System.Security.Cryptography.Native.Apple/CMakeLists.txt | 2 ++ 2 files changed, 6 insertions(+) diff --git a/src/native/libs/System.Native/CMakeLists.txt b/src/native/libs/System.Native/CMakeLists.txt index 8fa04ec15a9c9e..ec3c2c4c6f97c5 100644 --- a/src/native/libs/System.Native/CMakeLists.txt +++ b/src/native/libs/System.Native/CMakeLists.txt @@ -112,6 +112,10 @@ endif () include(${CMAKE_CURRENT_LIST_DIR}/extra_libs.cmake) +if (CLR_CMAKE_TARGET_APPLE) + add_compile_options(-gline-tables-only) +endif() + set(NATIVE_LIBS_EXTRA) append_extra_system_libs(NATIVE_LIBS_EXTRA) diff --git a/src/native/libs/System.Security.Cryptography.Native.Apple/CMakeLists.txt b/src/native/libs/System.Security.Cryptography.Native.Apple/CMakeLists.txt index 99f7b1b2d207f6..0fb4fb923aa4a7 100644 --- a/src/native/libs/System.Security.Cryptography.Native.Apple/CMakeLists.txt +++ b/src/native/libs/System.Security.Cryptography.Native.Apple/CMakeLists.txt @@ -2,6 +2,8 @@ project(System.Security.Cryptography.Native.Apple C) include(${CMAKE_CURRENT_LIST_DIR}/extra_libs.cmake) +add_compile_options(-gline-tables-only) + set(NATIVE_LIBS_EXTRA) append_extra_cryptography_apple_libs(NATIVE_LIBS_EXTRA) From 6ade1efcacc7edfc4694088581474a2fa66f053a Mon Sep 17 00:00:00 2001 From: Milos Kotlar Date: Fri, 13 Mar 2026 11:44:00 +0100 Subject: [PATCH 5/8] Fix PCM errors by centralizing -gline-tables-only and using -gnone for Swift Move -gline-tables-only from individual library CMakeLists.txt to the central src/native/libs/CMakeLists.txt for all Apple targets. This covers all native libraries (System.Native, System.Globalization.Native, System.Net.Security.Native, System.IO.Compression.Native, System.Security.Cryptography.Native.Apple) preventing dsymutil from encountering stale clang module cache references. For Swift compilation (pal_swiftbindings.swift), change from -gline-tables-only to -gnone because the Swift compiler emits DW_TAG_module entries (Foundation, _SwiftConcurrencyShims, CryptoKit) even with -gline-tables-only, causing dsymutil to fail looking for PCM files in the clang module cache. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/native/libs/CMakeLists.txt | 1 + src/native/libs/System.Native/CMakeLists.txt | 4 ---- .../System.Security.Cryptography.Native.Apple/CMakeLists.txt | 4 +--- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/native/libs/CMakeLists.txt b/src/native/libs/CMakeLists.txt index 10b9174e9f6da3..818dc5bbe27ae1 100644 --- a/src/native/libs/CMakeLists.txt +++ b/src/native/libs/CMakeLists.txt @@ -104,6 +104,7 @@ if (CLR_CMAKE_TARGET_UNIX OR CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI) if (CLR_CMAKE_TARGET_APPLE) add_definitions(-D__APPLE_USE_RFC_3542) + add_compile_options(-gline-tables-only) endif () if (CLR_CMAKE_TARGET_LINUX OR CLR_CMAKE_TARGET_HAIKU) diff --git a/src/native/libs/System.Native/CMakeLists.txt b/src/native/libs/System.Native/CMakeLists.txt index ec3c2c4c6f97c5..8fa04ec15a9c9e 100644 --- a/src/native/libs/System.Native/CMakeLists.txt +++ b/src/native/libs/System.Native/CMakeLists.txt @@ -112,10 +112,6 @@ endif () include(${CMAKE_CURRENT_LIST_DIR}/extra_libs.cmake) -if (CLR_CMAKE_TARGET_APPLE) - add_compile_options(-gline-tables-only) -endif() - set(NATIVE_LIBS_EXTRA) append_extra_system_libs(NATIVE_LIBS_EXTRA) diff --git a/src/native/libs/System.Security.Cryptography.Native.Apple/CMakeLists.txt b/src/native/libs/System.Security.Cryptography.Native.Apple/CMakeLists.txt index 0fb4fb923aa4a7..cbb8c439b7b517 100644 --- a/src/native/libs/System.Security.Cryptography.Native.Apple/CMakeLists.txt +++ b/src/native/libs/System.Security.Cryptography.Native.Apple/CMakeLists.txt @@ -2,8 +2,6 @@ project(System.Security.Cryptography.Native.Apple C) include(${CMAKE_CURRENT_LIST_DIR}/extra_libs.cmake) -add_compile_options(-gline-tables-only) - set(NATIVE_LIBS_EXTRA) append_extra_cryptography_apple_libs(NATIVE_LIBS_EXTRA) @@ -91,7 +89,7 @@ endif() add_custom_command( OUTPUT pal_swiftbindings.o - COMMAND xcrun swiftc -emit-object -static -parse-as-library -enable-library-evolution ${SWIFT_COMPILER_ERRORS_FLAG} -gline-tables-only ${SWIFT_OPTIMIZATION_FLAG} -runtime-compatibility-version none ${SWIFT_SDK_FLAG} -target ${SWIFT_COMPILER_TARGET} ${CMAKE_CURRENT_SOURCE_DIR}/pal_swiftbindings.swift -o pal_swiftbindings.o + COMMAND xcrun swiftc -emit-object -static -parse-as-library -enable-library-evolution ${SWIFT_COMPILER_ERRORS_FLAG} -gnone ${SWIFT_OPTIMIZATION_FLAG} -runtime-compatibility-version none ${SWIFT_SDK_FLAG} -target ${SWIFT_COMPILER_TARGET} ${CMAKE_CURRENT_SOURCE_DIR}/pal_swiftbindings.swift -o pal_swiftbindings.o MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/pal_swiftbindings.swift COMMENT "Compiling Swift file pal_swiftbindings.swift" ) From 245cbd04b05549da4534c87393a66f23e6cf3ebc Mon Sep 17 00:00:00 2001 From: Milos Kotlar Date: Mon, 16 Mar 2026 12:40:30 +0100 Subject: [PATCH 6/8] Ignore dsymutil non-fatal .pcm warnings during Apple symbol stripping Apple's pre-built Swift runtime static libraries (swiftCore, swiftFoundation) contain DWARF debug info with -gmodules references to .pcm module cache files that only existed on Apple's build machines. dsymutil outputs 'error:' for these missing files but exits with code 0 (non-fatal). MSBuild's Exec task parses output for 'error:' patterns and incorrectly treats them as build errors. Adding IgnoreStandardErrorWarningFormat makes MSBuild rely on the exit code instead of output parsing, so non-fatal dsymutil warnings no longer break the build while real errors (non-zero exit code) still fail correctly. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets | 1 + src/tasks/Crossgen2Tasks/Microsoft.NET.CrossGen.targets | 1 + 2 files changed, 2 insertions(+) diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets index e758f681c3c0ee..a72bddff0929d1 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets @@ -413,6 +413,7 @@ The .NET Foundation licenses this file to you under the MIT license. Command=""$(ObjCopyName)" --add-gnu-debuglink="$(NativeBinary)$(NativeSymbolExt)" "$(NativeBinary)"" /> diff --git a/src/tasks/Crossgen2Tasks/Microsoft.NET.CrossGen.targets b/src/tasks/Crossgen2Tasks/Microsoft.NET.CrossGen.targets index e20b05ee033e52..a7a3ce1b726f33 100644 --- a/src/tasks/Crossgen2Tasks/Microsoft.NET.CrossGen.targets +++ b/src/tasks/Crossgen2Tasks/Microsoft.NET.CrossGen.targets @@ -665,6 +665,7 @@ Copyright (c) .NET Foundation. All rights reserved. From 19820c40eb4f1c5255e38516a5dfc48022cb8e05 Mon Sep 17 00:00:00 2001 From: Milos Kotlar Date: Mon, 16 Mar 2026 17:39:49 +0100 Subject: [PATCH 7/8] Suppress dsymutil stderr for tool AOT publish on Apple platforms The NativeAOT SDK targets invoke dsymutil during symbol stripping. Apple's pre-built Swift runtime static libraries contain -gmodules debug info with references to .pcm module cache files that don't exist on build machines. dsymutil outputs 'error:' for these missing files but exits 0 (non-fatal). MSBuild's Exec task parses the output and treats them as build errors. The tool AOT publish (ILCompiler, crossgen2, XUnitLogChecker) uses the SDK's NativeAOT targets, not the source-tree targets, so the IgnoreStandardError WarningFormat fix in Microsoft.NETCore.Native.targets doesn't apply here. Redirecting dsymutil stderr via DsymUtilOptions suppresses the non-fatal warnings while preserving exit code based error detection. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- eng/toolAot.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/toolAot.targets b/eng/toolAot.targets index e378f44ddbc128..d6850442bc6814 100644 --- a/eng/toolAot.targets +++ b/eng/toolAot.targets @@ -5,7 +5,7 @@ true .dwarf - --flat + --flat 2>/dev/null From a3583b7fb3f87adbb4ecb8e547129fdcc8429e45 Mon Sep 17 00:00:00 2001 From: Milos Kotlar Date: Tue, 17 Mar 2026 17:28:22 +0100 Subject: [PATCH 8/8] Refactor Apple platform detection and symbol stripping options in AOT publishing --- eng/toolAot.targets | 9 +++++++-- src/native/managed/native-library.targets | 2 +- src/tools/ilasm/src/ilasm/ilasm.csproj | 3 --- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/eng/toolAot.targets b/eng/toolAot.targets index d6850442bc6814..ee0470957be1f3 100644 --- a/eng/toolAot.targets +++ b/eng/toolAot.targets @@ -3,9 +3,14 @@ true + + <_IsApplePlatformToolAot Condition="'$(PortableOS)' == 'osx' or '$(PortableOS)' == 'ios' or '$(PortableOS)' == 'iossimulator' or '$(PortableOS)' == 'tvos' or '$(PortableOS)' == 'tvossimulator' or '$(PortableOS)' == 'maccatalyst'">true - .dwarf - --flat 2>/dev/null + .dwarf + --flat 2>/dev/null diff --git a/src/native/managed/native-library.targets b/src/native/managed/native-library.targets index 298da3c50ce786..692de5315276ba 100644 --- a/src/native/managed/native-library.targets +++ b/src/native/managed/native-library.targets @@ -70,7 +70,7 @@ <_StripLike Condition="'$(_StripLike)' == ''">gnu - + diff --git a/src/tools/ilasm/src/ilasm/ilasm.csproj b/src/tools/ilasm/src/ilasm/ilasm.csproj index 1ed88edd74622d..8a1e3d9fe0a6b4 100644 --- a/src/tools/ilasm/src/ilasm/ilasm.csproj +++ b/src/tools/ilasm/src/ilasm/ilasm.csproj @@ -12,9 +12,6 @@ true true true - - - false enable