From 840ee5bcbf2707755f11c888162d487ab3cd06f0 Mon Sep 17 00:00:00 2001 From: Milos Kotlar Date: Wed, 25 Jan 2023 09:44:16 +0100 Subject: [PATCH 1/6] Add build option to strip out debug symbols when building MonoAOT iOS sample app --- src/mono/sample/iOS/Makefile | 3 + src/mono/sample/iOS/Program.csproj | 5 ++ src/mono/sample/iOS/symbols.list | 111 +++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 src/mono/sample/iOS/symbols.list diff --git a/src/mono/sample/iOS/Makefile b/src/mono/sample/iOS/Makefile index 01ae748bbda1a..b66e38670e033 100644 --- a/src/mono/sample/iOS/Makefile +++ b/src/mono/sample/iOS/Makefile @@ -6,6 +6,7 @@ AOT?=false TARGET?=iossimulator DEPLOY_AND_RUN?=true APP_SANDBOX?=false +STRIP_DEBUG_SYMBOLS?=false #If DIAGNOSTIC_PORTS is enabled, RUNTIME_COMPONENTS must also be enabled. #If RUNTIME_COMPONENTS is enabled, DIAGNOSTIC_PORTS is optional. @@ -33,6 +34,7 @@ run: clean appbuilder /p:TargetArchitecture=$(MONO_ARCH) \ /p:UseLLVM=$(USE_LLVM) \ /p:ForceAOT=$(AOT) \ + /p:StripDebugSymbols=$(STRIP_DEBUG_SYMBOLS) \ '/p:RuntimeComponents="$(RUNTIME_COMPONENTS)"' \ '/p:DeployAndRun="$(DEPLOY_AND_RUN)"' \ '/p:DiagnosticPorts="$(DIAGNOSTIC_PORTS)"' @@ -44,6 +46,7 @@ run-sim: clean appbuilder /p:TargetArchitecture=$(MONO_ARCH) \ /p:UseLLVM=$(USE_LLVM) \ /p:ForceAOT=$(AOT) \ + /p:StripDebugSymbols=$(STRIP_DEBUG_SYMBOLS) \ '/p:RuntimeComponents="$(RUNTIME_COMPONENTS)"' \ '/p:DeployAndRun="$(DEPLOY_AND_RUN)"' \ '/p:DiagnosticPorts="$(DIAGNOSTIC_PORTS)"' diff --git a/src/mono/sample/iOS/Program.csproj b/src/mono/sample/iOS/Program.csproj index 765658d4837d8..953f9d4db7953 100644 --- a/src/mono/sample/iOS/Program.csproj +++ b/src/mono/sample/iOS/Program.csproj @@ -9,6 +9,7 @@ $(TargetOS)-$(TargetArchitecture) $(DefineConstants);CI_TEST HelloiOS + false @@ -97,6 +98,10 @@ + + diff --git a/src/mono/sample/iOS/symbols.list b/src/mono/sample/iOS/symbols.list new file mode 100644 index 0000000000000..256506b5f2352 --- /dev/null +++ b/src/mono/sample/iOS/symbols.list @@ -0,0 +1,111 @@ +_SystemNative_Abort +_SystemNative_Exit +_SystemNative_SchedGetCpu +_SystemNative_ConvertErrorPlatformToPal +_SystemNative_ConvertErrorPalToPlatform +_SystemNative_StrErrorR +_SystemNative_GetLoadLibraryError +_SystemNative_GetProcAddress +_SystemNative_FreeLibrary +_SystemNative_GetErrNo +_SystemNative_SetErrNo +_SystemNative_GetEnviron +_SystemNative_FreeEnviron +_SystemNative_GetOSArchitecture +_SystemNative_GetNonCryptographicallySecureRandomBytes +_SystemNative_GetCryptographicallySecureRandomBytes +_SystemNative_GetSystemTimeAsTicks +_SystemNative_GetTimestamp +_SystemNative_LChflagsCanSetHiddenFlag +_SystemNative_CanGetHiddenFlag +_SystemNative_Log +_SystemNative_LogError +_SystemNative_LowLevelMonitor_Create +_SystemNative_LowLevelMonitor_Destroy +_SystemNative_LowLevelMonitor_Acquire +_SystemNative_LowLevelMonitor_Release +_SystemNative_LowLevelMonitor_Wait +_SystemNative_LowLevelMonitor_Signal_Release +_SystemNative_AlignedAlloc +_SystemNative_AlignedFree +_SystemNative_AlignedRealloc +_SystemNative_Calloc +_SystemNative_Free +_SystemNative_Malloc +_SystemNative_Realloc +_SystemNative_GetAllMountPoints +_SystemNative_GetReadDirRBufferSize +_SystemNative_ReadDirR +_SystemNative_GetEUid +_SystemNative_GetEGid +_SystemNative_GetPid +_SystemNative_CreateAutoreleasePool +_SystemNative_DrainAutoreleasePool +_SystemNative_CreateThread +_SystemNative_Access +_SystemNative_ChDir +_SystemNative_ChMod +_SystemNative_FChMod +_SystemNative_Close +_SystemNative_CopyFile +_SystemNative_LoadLibrary +_SystemNative_GetDefaultSearchOrderPseudoHandle +_SystemNative_GetFileSystemType +_SystemNative_FLock +_SystemNative_FSync +_SystemNative_FTruncate +_SystemNative_GetCpuUtilization +_SystemNative_GetCwd +_SystemNative_GetDefaultTimeZone +_SystemNative_GetEnv +_SystemNative_GetHostName +_SystemNative_GetProcessPath +_SystemNative_GetUnixVersion +_SystemNative_GetUnixRelease +_SystemNative_LChflags +_SystemNative_FChflags +_SystemNative_Link +_SystemNative_LockFileRegion +_SystemNative_LowLevelMonitor_TimedWait +_SystemNative_LSeek +_SystemNative_MkDir +_SystemNative_MkdTemp +_SystemNative_MksTemps +_SystemNative_Open +_SystemNative_PathConf +_SystemNative_PosixFAdvise +_SystemNative_FAllocate +_SystemNative_PRead +_SystemNative_PReadV +_SystemNative_PWrite +_SystemNative_PWriteV +_SystemNative_Read +_SystemNative_OpenDir +_SystemNative_CloseDir +_SystemNative_ReadLink +_SystemNative_Rename +_SystemNative_RmDir +_SystemNative_FStat +_SystemNative_Stat +_SystemNative_LStat +_SystemNative_SymLink +_SystemNative_SysConf +_SystemNative_SysLog +_SystemNative_Unlink +_SystemNative_UTimensat +_SystemNative_FUTimens +_SystemNative_Write +_SystemNative_GetGroups +_SystemNative_GetPwUidR +_SystemNative_GetPwNamR +_SystemNative_SearchPath +_SystemNative_SearchPath_TempDirectory +_SystemNative_FcntlSetFD +_SystemNative_MMap +_SystemNative_MUnmap +_SystemNative_MSync +_SystemNative_MAdvise +_SystemNative_ShmOpen +_SystemNative_ShmUnlink +_ios_register_button_click +_ios_set_text \ No newline at end of file From 5fc415bd2f8cd2909cf674ff1bedee31b9275366 Mon Sep 17 00:00:00 2001 From: Milos Kotlar Date: Mon, 30 Jan 2023 16:16:01 +0100 Subject: [PATCH 2/6] Strip symbols when measuring SOD via build-appbundle make target --- src/mono/sample/iOS/Makefile | 5 ++--- src/mono/sample/iOS/Program.csproj | 2 +- src/mono/sample/iOS/{symbols.list => symbols_to_keep.list} | 0 3 files changed, 3 insertions(+), 4 deletions(-) rename src/mono/sample/iOS/{symbols.list => symbols_to_keep.list} (100%) diff --git a/src/mono/sample/iOS/Makefile b/src/mono/sample/iOS/Makefile index b66e38670e033..0fd8bc8790532 100644 --- a/src/mono/sample/iOS/Makefile +++ b/src/mono/sample/iOS/Makefile @@ -6,7 +6,7 @@ AOT?=false TARGET?=iossimulator DEPLOY_AND_RUN?=true APP_SANDBOX?=false -STRIP_DEBUG_SYMBOLS?=false +STRIP_DEBUG_SYMBOLS?=true // 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. @@ -34,7 +34,6 @@ run: clean appbuilder /p:TargetArchitecture=$(MONO_ARCH) \ /p:UseLLVM=$(USE_LLVM) \ /p:ForceAOT=$(AOT) \ - /p:StripDebugSymbols=$(STRIP_DEBUG_SYMBOLS) \ '/p:RuntimeComponents="$(RUNTIME_COMPONENTS)"' \ '/p:DeployAndRun="$(DEPLOY_AND_RUN)"' \ '/p:DiagnosticPorts="$(DIAGNOSTIC_PORTS)"' @@ -46,7 +45,6 @@ run-sim: clean appbuilder /p:TargetArchitecture=$(MONO_ARCH) \ /p:UseLLVM=$(USE_LLVM) \ /p:ForceAOT=$(AOT) \ - /p:StripDebugSymbols=$(STRIP_DEBUG_SYMBOLS) \ '/p:RuntimeComponents="$(RUNTIME_COMPONENTS)"' \ '/p:DeployAndRun="$(DEPLOY_AND_RUN)"' \ '/p:DiagnosticPorts="$(DIAGNOSTIC_PORTS)"' @@ -54,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: diff --git a/src/mono/sample/iOS/Program.csproj b/src/mono/sample/iOS/Program.csproj index 953f9d4db7953..e5395d5474ee4 100644 --- a/src/mono/sample/iOS/Program.csproj +++ b/src/mono/sample/iOS/Program.csproj @@ -100,7 +100,7 @@ + strip -no_code_signature_warning -i -s $(MSBuildThisFileDirectory)/symbols_to_keep.list $(AppBundlePath)/$(AppName)" /> diff --git a/src/mono/sample/iOS/symbols.list b/src/mono/sample/iOS/symbols_to_keep.list similarity index 100% rename from src/mono/sample/iOS/symbols.list rename to src/mono/sample/iOS/symbols_to_keep.list From c32fefb8dafffc99bedcc6e89ab7d5cf5a69b5c5 Mon Sep 17 00:00:00 2001 From: Milos Kotlar Date: Tue, 31 Jan 2023 12:10:00 +0100 Subject: [PATCH 3/6] Disable symbol stripping by default --- src/mono/sample/iOS/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/sample/iOS/Makefile b/src/mono/sample/iOS/Makefile index 0fd8bc8790532..f8eaede36020b 100644 --- a/src/mono/sample/iOS/Makefile +++ b/src/mono/sample/iOS/Makefile @@ -6,7 +6,7 @@ AOT?=false TARGET?=iossimulator DEPLOY_AND_RUN?=true APP_SANDBOX?=false -STRIP_DEBUG_SYMBOLS?=true // only used when measuring SOD via build-appbundle make target +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. From 5c03de9a764952a9649e5d5df311c5d71645ccef Mon Sep 17 00:00:00 2001 From: Milos Kotlar Date: Tue, 31 Jan 2023 13:23:23 +0100 Subject: [PATCH 4/6] Extract symbols in publish directory --- src/mono/sample/iOS/Program.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/sample/iOS/Program.csproj b/src/mono/sample/iOS/Program.csproj index e5395d5474ee4..3c5635e01cb0e 100644 --- a/src/mono/sample/iOS/Program.csproj +++ b/src/mono/sample/iOS/Program.csproj @@ -99,7 +99,7 @@ From 5c3674e21897a646d9f7f7f19ff2d590de7ef3d8 Mon Sep 17 00:00:00 2001 From: Milos Kotlar Date: Tue, 31 Jan 2023 20:33:44 +0100 Subject: [PATCH 5/6] Add debug stripping in AppleAppBuilder task. Strip local symbols and debug information. --- src/mono/sample/iOS/Program.csproj | 5 +- src/mono/sample/iOS/symbols_to_keep.list | 111 ------------------- src/tasks/AppleAppBuilder/AppleAppBuilder.cs | 6 +- src/tasks/AppleAppBuilder/Xcode.cs | 15 ++- 4 files changed, 19 insertions(+), 118 deletions(-) delete mode 100644 src/mono/sample/iOS/symbols_to_keep.list diff --git a/src/mono/sample/iOS/Program.csproj b/src/mono/sample/iOS/Program.csproj index 3c5635e01cb0e..00f7e447f0409 100644 --- a/src/mono/sample/iOS/Program.csproj +++ b/src/mono/sample/iOS/Program.csproj @@ -93,15 +93,12 @@ RuntimeComponents="$(RuntimeComponents)" EnableAppSandbox="$(EnableAppSandbox)" DiagnosticPorts="$(DiagnosticPorts)" + StripSymbolTable="$(StripDebugSymbols)" AppDir="$(MSBuildThisFileDirectory)$(PublishDir)"> - - diff --git a/src/mono/sample/iOS/symbols_to_keep.list b/src/mono/sample/iOS/symbols_to_keep.list deleted file mode 100644 index 256506b5f2352..0000000000000 --- a/src/mono/sample/iOS/symbols_to_keep.list +++ /dev/null @@ -1,111 +0,0 @@ -_SystemNative_Abort -_SystemNative_Exit -_SystemNative_SchedGetCpu -_SystemNative_ConvertErrorPlatformToPal -_SystemNative_ConvertErrorPalToPlatform -_SystemNative_StrErrorR -_SystemNative_GetLoadLibraryError -_SystemNative_GetProcAddress -_SystemNative_FreeLibrary -_SystemNative_GetErrNo -_SystemNative_SetErrNo -_SystemNative_GetEnviron -_SystemNative_FreeEnviron -_SystemNative_GetOSArchitecture -_SystemNative_GetNonCryptographicallySecureRandomBytes -_SystemNative_GetCryptographicallySecureRandomBytes -_SystemNative_GetSystemTimeAsTicks -_SystemNative_GetTimestamp -_SystemNative_LChflagsCanSetHiddenFlag -_SystemNative_CanGetHiddenFlag -_SystemNative_Log -_SystemNative_LogError -_SystemNative_LowLevelMonitor_Create -_SystemNative_LowLevelMonitor_Destroy -_SystemNative_LowLevelMonitor_Acquire -_SystemNative_LowLevelMonitor_Release -_SystemNative_LowLevelMonitor_Wait -_SystemNative_LowLevelMonitor_Signal_Release -_SystemNative_AlignedAlloc -_SystemNative_AlignedFree -_SystemNative_AlignedRealloc -_SystemNative_Calloc -_SystemNative_Free -_SystemNative_Malloc -_SystemNative_Realloc -_SystemNative_GetAllMountPoints -_SystemNative_GetReadDirRBufferSize -_SystemNative_ReadDirR -_SystemNative_GetEUid -_SystemNative_GetEGid -_SystemNative_GetPid -_SystemNative_CreateAutoreleasePool -_SystemNative_DrainAutoreleasePool -_SystemNative_CreateThread -_SystemNative_Access -_SystemNative_ChDir -_SystemNative_ChMod -_SystemNative_FChMod -_SystemNative_Close -_SystemNative_CopyFile -_SystemNative_LoadLibrary -_SystemNative_GetDefaultSearchOrderPseudoHandle -_SystemNative_GetFileSystemType -_SystemNative_FLock -_SystemNative_FSync -_SystemNative_FTruncate -_SystemNative_GetCpuUtilization -_SystemNative_GetCwd -_SystemNative_GetDefaultTimeZone -_SystemNative_GetEnv -_SystemNative_GetHostName -_SystemNative_GetProcessPath -_SystemNative_GetUnixVersion -_SystemNative_GetUnixRelease -_SystemNative_LChflags -_SystemNative_FChflags -_SystemNative_Link -_SystemNative_LockFileRegion -_SystemNative_LowLevelMonitor_TimedWait -_SystemNative_LSeek -_SystemNative_MkDir -_SystemNative_MkdTemp -_SystemNative_MksTemps -_SystemNative_Open -_SystemNative_PathConf -_SystemNative_PosixFAdvise -_SystemNative_FAllocate -_SystemNative_PRead -_SystemNative_PReadV -_SystemNative_PWrite -_SystemNative_PWriteV -_SystemNative_Read -_SystemNative_OpenDir -_SystemNative_CloseDir -_SystemNative_ReadLink -_SystemNative_Rename -_SystemNative_RmDir -_SystemNative_FStat -_SystemNative_Stat -_SystemNative_LStat -_SystemNative_SymLink -_SystemNative_SysConf -_SystemNative_SysLog -_SystemNative_Unlink -_SystemNative_UTimensat -_SystemNative_FUTimens -_SystemNative_Write -_SystemNative_GetGroups -_SystemNative_GetPwUidR -_SystemNative_GetPwNamR -_SystemNative_SearchPath -_SystemNative_SearchPath_TempDirectory -_SystemNative_FcntlSetFD -_SystemNative_MMap -_SystemNative_MUnmap -_SystemNative_MSync -_SystemNative_MAdvise -_SystemNative_ShmOpen -_SystemNative_ShmUnlink -_ios_register_button_click -_ios_set_text \ No newline at end of file diff --git a/src/tasks/AppleAppBuilder/AppleAppBuilder.cs b/src/tasks/AppleAppBuilder/AppleAppBuilder.cs index 193e047efc68a..c375de7f1db4a 100644 --- a/src/tasks/AppleAppBuilder/AppleAppBuilder.cs +++ b/src/tasks/AppleAppBuilder/AppleAppBuilder.cs @@ -163,6 +163,10 @@ public string TargetOS /// public bool EnableAppSandbox { get; set; } + /// Strip local symbols and debug information, and extract it in XcodeProjectPath directory + /// + public bool StripSymbolTable { get; set; } + public override bool Execute() { bool isDevice = (TargetOS == TargetNames.iOS || TargetOS == TargetNames.tvOS); @@ -263,7 +267,7 @@ public override bool Execute() } else { - AppBundlePath = generator.BuildAppBundle(XcodeProjectPath, Optimized, DevTeamProvisioning); + AppBundlePath = generator.BuildAppBundle(XcodeProjectPath, Optimized, StripSymbolTable, DevTeamProvisioning); } } } diff --git a/src/tasks/AppleAppBuilder/Xcode.cs b/src/tasks/AppleAppBuilder/Xcode.cs index 227ff3752d234..87ee14283e1e5 100644 --- a/src/tasks/AppleAppBuilder/Xcode.cs +++ b/src/tasks/AppleAppBuilder/Xcode.cs @@ -103,9 +103,13 @@ public string TargetOS /// public string? DestinationFolder { get; set; } + /// Strip local symbols and debug information, and extract it in XcodeProjectPath directory + /// + 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 @@ 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(); @@ -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); From 60eecc077a450bf538255ebdbd610619cc6387f4 Mon Sep 17 00:00:00 2001 From: Milos Kotlar Date: Thu, 2 Feb 2023 17:43:38 +0100 Subject: [PATCH 6/6] Fix comment typo --- src/mono/sample/iOS/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/sample/iOS/Makefile b/src/mono/sample/iOS/Makefile index f8eaede36020b..ef24938c6fd30 100644 --- a/src/mono/sample/iOS/Makefile +++ b/src/mono/sample/iOS/Makefile @@ -6,7 +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 +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.