[mono][ios] Introduce non-global symbol stripping in MonoAOTCompiler msbuild task...
authorMilos Kotlar <kotlarmilos@gmail.com>
Thu, 2 Feb 2023 19:03:17 +0000 (20:03 +0100)
committerGitHub <noreply@github.com>
Thu, 2 Feb 2023 19:03:17 +0000 (20:03 +0100)
* Add non-global symbol stripping in AppleAppBuilder task.

* Strip symbols when measuring SOD via build-appbundle make target

src/mono/sample/iOS/Makefile
src/mono/sample/iOS/Program.csproj
src/tasks/AppleAppBuilder/AppleAppBuilder.cs
src/tasks/AppleAppBuilder/Xcode.cs

index 01ae748..ef24938 100644 (file)
@@ -6,6 +6,7 @@ AOT?=false
 TARGET?=iossimulator
 DEPLOY_AND_RUN?=true
 APP_SANDBOX?=false
+STRIP_DEBUG_SYMBOLS?=false # only used when measuring SOD via build-appbundle make target
 
 #If DIAGNOSTIC_PORTS is enabled, RUNTIME_COMPONENTS must also be enabled.
 #If RUNTIME_COMPONENTS is enabled, DIAGNOSTIC_PORTS is optional.
@@ -51,6 +52,7 @@ run-sim: clean appbuilder
 build-appbundle: clean appbuilder
        $(DOTNET) publish -c $(MONO_CONFIG) /p:TargetOS=$(TARGET) /p:TargetArchitecture=$(MONO_ARCH) \
        '/p:DeployAndRun="$(DEPLOY_AND_RUN)"' \
+       /p:StripDebugSymbols=$(STRIP_DEBUG_SYMBOLS) \
        /p:UseLLVM=$(USE_LLVM) /p:ForceAOT=$(AOT) /bl \
 
 run-catalyst:
index 765658d..00f7e44 100644 (file)
@@ -9,6 +9,7 @@
     <RuntimeIdentifier>$(TargetOS)-$(TargetArchitecture)</RuntimeIdentifier>
     <DefineConstants Condition="'$(ArchiveTests)' == 'true'">$(DefineConstants);CI_TEST</DefineConstants>
     <AppName>HelloiOS</AppName>
+    <StripDebugSymbols Condition="'$(StripDebugSymbols)' == ''">false</StripDebugSymbols>
   </PropertyGroup>
 
   <PropertyGroup>
@@ -92,6 +93,7 @@
         RuntimeComponents="$(RuntimeComponents)"
         EnableAppSandbox="$(EnableAppSandbox)"
         DiagnosticPorts="$(DiagnosticPorts)"
+        StripSymbolTable="$(StripDebugSymbols)"
         AppDir="$(MSBuildThisFileDirectory)$(PublishDir)">
         <Output TaskParameter="AppBundlePath" PropertyName="AppBundlePath" />
         <Output TaskParameter="XcodeProjectPath" PropertyName="XcodeProjectPath" />
index 193e047..c375de7 100644 (file)
@@ -163,6 +163,10 @@ public class AppleAppBuilderTask : Task
     /// </summary>
     public bool EnableAppSandbox { get; set; }
 
+    /// Strip local symbols and debug information, and extract it in XcodeProjectPath directory
+    /// </summary>
+    public bool StripSymbolTable { get; set; }
+
     public override bool Execute()
     {
         bool isDevice = (TargetOS == TargetNames.iOS || TargetOS == TargetNames.tvOS);
@@ -263,7 +267,7 @@ public class AppleAppBuilderTask : Task
                 }
                 else
                 {
-                    AppBundlePath = generator.BuildAppBundle(XcodeProjectPath, Optimized, DevTeamProvisioning);
+                    AppBundlePath = generator.BuildAppBundle(XcodeProjectPath, Optimized, StripSymbolTable, DevTeamProvisioning);
                 }
             }
         }
index 227ff37..87ee142 100644 (file)
@@ -103,9 +103,13 @@ public class XcodeBuildApp : Task
     /// </summary>
     public string? DestinationFolder { get; set; }
 
+    /// Strip local symbols and debug information, and extract it in XcodeProjectPath directory
+    /// </summary>
+    public bool StripSymbolTable { get; set; }
+
     public override bool Execute()
     {
-        new Xcode(Log, TargetOS, Arch).BuildAppBundle(XcodeProjectPath, Optimized, DevTeamProvisioning, DestinationFolder);
+        new Xcode(Log, TargetOS, Arch).BuildAppBundle(XcodeProjectPath, Optimized, StripSymbolTable, DevTeamProvisioning, DestinationFolder);
 
         return true;
     }
@@ -440,7 +444,7 @@ internal sealed class Xcode
     }
 
     public string BuildAppBundle(
-        string xcodePrjPath, bool optimized, string? devTeamProvisioning = null, string? destination = null)
+        string xcodePrjPath, bool optimized, bool stripSymbolTable, string? devTeamProvisioning = null, string? destination = null)
     {
         string sdk = "";
         var args = new StringBuilder();
@@ -545,6 +549,13 @@ internal sealed class Xcode
             appPath = newAppPath;
         }
 
+        if (stripSymbolTable)
+        {
+            string filename = Path.GetFileNameWithoutExtension(appPath);
+            Utils.RunProcess(Logger, "dsymutil", $"{appPath}/{filename} -o {Path.GetDirectoryName(xcodePrjPath)}/{filename}.dSYM", workingDir: Path.GetDirectoryName(appPath));
+            Utils.RunProcess(Logger, "strip", $"-no_code_signature_warning -x {appPath}/{filename}", workingDir: Path.GetDirectoryName(appPath));
+        }
+
         long appSize = new DirectoryInfo(appPath)
             .EnumerateFiles("*", SearchOption.AllDirectories)
             .Sum(file => file.Length);