Skip to content

Commit

Permalink
[mono][ios] Introduce non-global symbol stripping in MonoAOTCompiler …
Browse files Browse the repository at this point in the history
…msbuild task (#81361)

* Add non-global symbol stripping in AppleAppBuilder task.

* Strip symbols when measuring SOD via build-appbundle make target
  • Loading branch information
kotlarmilos committed Feb 2, 2023
1 parent 2411d09 commit eec29a1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/mono/sample/iOS/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions src/mono/sample/iOS/Program.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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" />
Expand Down
6 changes: 5 additions & 1 deletion src/tasks/AppleAppBuilder/AppleAppBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ public string TargetOS
/// </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);
Expand Down Expand Up @@ -263,7 +267,7 @@ public override bool Execute()
}
else
{
AppBundlePath = generator.BuildAppBundle(XcodeProjectPath, Optimized, DevTeamProvisioning);
AppBundlePath = generator.BuildAppBundle(XcodeProjectPath, Optimized, StripSymbolTable, DevTeamProvisioning);
}
}
}
Expand Down
15 changes: 13 additions & 2 deletions src/tasks/AppleAppBuilder/Xcode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,13 @@ public string TargetOS
/// </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;
}
Expand Down Expand Up @@ -440,7 +444,7 @@ public string GenerateCMake(
}

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();
Expand Down Expand Up @@ -545,6 +549,13 @@ public string BuildAppBundle(
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);
Expand Down

0 comments on commit eec29a1

Please sign in to comment.