Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[net6] Strip framework native libraries #5637

Merged

Conversation

radekdoulik
Copy link
Member

@radekdoulik radekdoulik commented Feb 18, 2021

Context: #5558
Context: dotnet/runtime#45013

Due to runtime issue #45013 we are producing large packages
for Release configurations, where native libraries contain debug
information.

So we will strip framework native libs for now. Added new target
and task to call ndk's strip tool with --strip-debug option.
The target should work partially.

The apk sizes differences, before/after BuildReleaseArm64False/net6:

Size difference in bytes ([*1] apk1 only, [*2] apk2 only):
  +         296 lib/arm64-v8a/libxa-internal-api.so
  -         560 lib/arm64-v8a/libmonodroid.so
  -     168,344 lib/arm64-v8a/libxamarin-debug-app-helper.so
  -  14,762,720 lib/arm64-v8a/libmonosgen-2.0.so
Summary:
  +           0 Other entries 0.00% (of 58,624)
  +           0 Dalvik executables 0.00% (of 316,988)
  +           0 Assemblies 0.00% (of 690,435)
  -  14,931,328 Shared libraries -74.17% (of 20,130,552)
  +           0 Uncompressed assemblies 0.00% (of 1,357,824)
  -   4,947,968 Package size difference -62.74% (of 7,886,783)

Interestingly, the size of libxa-internal-api.so increases, only marginally though.

That get us back to much better ratio between apk sizes of legacy and net6 (BuildReleaseArm64False):

Summary:
  +         603 Other entries 1.04% (of 58,021)
  +          32 Dalvik executables 0.01% (of 316,956)
  -     463,004 Assemblies -40.14% (of 1,153,439)
  -   5,314,304 Shared libraries -50.55% (of 10,513,528)
  -   1,408,000 Uncompressed assemblies -50.91% (of 2,765,824)
  -   2,072,341 Package size difference -41.35% (of 5,011,156)

and apk sizes for legacy/net6 (BuildReleaseArm64True):

Summary:
  +      13,527 Other entries 1.50% (of 903,720)
  +         616 Dalvik executables 0.02% (of 3,454,376)
  +   1,022,148 Assemblies 21.87% (of 4,674,167)
  -   5,310,496 Shared libraries -50.17% (of 10,584,912)
  +   1,545,728 Uncompressed assemblies 13.69% (of 11,293,696)
  -     572,295 Package size difference -5.43% (of 10,537,118)

@jonpryor
Copy link
Member

This change shouldn't be limited to just .NET 6 support.

This change should also remove all of the .d.so files from the installer, e.g.

We should likewise ensure that all .so files in the installer are not stripd, and that $(AndroidIncludeDebugSymbols) defaults to False for Release apps.

Related: it looks like we didn't strip all of our libs anyway!

% cp /Library/Frameworks/Xamarin.Android.framework/Versions/Current//lib/xamarin.android/xbuild/Xamarin/Android/lib/x86_64/libmono-android.release.so
% cp libmono-android.release.so libmono-android.release.so.bk
% $HOME/android-toolchain/ndk/toolchains/x86_64-4.9/prebuilt/darwin-x86_64/bin/x86_64-linux-android-strip libmono-android.release.so
% ls -l libmono-android.release.so*
-rwxr-xr-x  1 jon  staff  227488 Feb 18 21:06 libmono-android.release.so
-rwxr-xr-x  1 jon  staff  273520 Feb 18 21:06 libmono-android.release.so.bk

Unless we're already striping -- which it doesn't look like we are! -- this should save 46KB from our .apk size!

@radekdoulik
Copy link
Member Author

radekdoulik commented Feb 19, 2021

This change shouldn't be limited to just .NET 6 support.

Here I want to fix it just for NET6, so that we don't have big apks in net6 preview builds.

For complete overhaul of it I think we will need broader discussion. There are question like whether we want to have just single library with debug information. Usually the debug and release use also different optimization options. Or whether we could have the debug information in separate file(s).

Unless we're already striping -- which it doesn't look like we are! -- this should save 46KB from our .apk size!

It looks to me as we are already stripping debug information (strip --strip-debug ...), otherwise the difference would be much bigger. I think we cannot strip everything. @grendello, do you remember why we cannot strip everything? Or could we?

@radekdoulik radekdoulik changed the title [net6/WIP] Strip framework native libraries [net6] Strip framework native libraries Feb 22, 2021
@radekdoulik radekdoulik marked this pull request as ready for review February 22, 2021 21:59
@jonpryor
Copy link
Member

Please also add a unit test/update an existing test.

@radekdoulik radekdoulik force-pushed the pr-net6-strip-framework-native-libs branch from 0e2914d to 8ff1530 Compare February 23, 2021 09:53
@radekdoulik
Copy link
Member Author

Please also add a unit test/update an existing test.

I have updated the apk size reference files. That should catch the case when we don't strip the native libs.

radekdoulik and others added 3 commits February 23, 2021 15:25
* `@(_StrippedFrameworkNativeLibrary)` now uses -> operator so it has all metadata
* We now have `SourceFiles` and `DestinationFiles` passed into the `<StripNativeLibraries/>` task
* Fixed spelling, I think it should be: tripple -> triple
* Updated a test so it check for stripped files on disk
This can be a ToolTask that runs itself N times. This way MSBuild can parse error/warning messages for us.
@radekdoulik radekdoulik merged commit fcd9c30 into dotnet:master Feb 24, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Jan 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants