Skip to content

Commit

Permalink
Do not include -dead_strip when native linking a NativeAOT object file (
Browse files Browse the repository at this point in the history
#18553)

This PR disables passing `-dead_strip` to the native linker in case of
NativeAOT runtime to prevent build failures.

Additionally, this change affects the size of the application in the
following way - measured with `dotnet new maui` app version
`8.0.0-preview.7.23359.1`:

| MAUI iOS | -dead_strip | no -dead_strip | diff (b) | diff (Kb) | diff
(%) |
|----------|--------------|----------|----------|-----------|----------|
| .ipa (b) | 13377583 | 13435276 | 57693 | 57,693 | 0,43% |
| Size on disk (b) | 41883897 | 42038873 | 154976 | 154,976 | 0,37% |
| binary (b) | 39614336 | 39769312 | 154976 | 154,976 | 0,39% |

Even though the size of the application regresses, with this change we
have a more stable product.

Finally, once this PR gets merged we can open a tracking issue to solve
the size regression either by fixing:
- dotnet/runtime#88032 or
- by manually removing the dead code as proposed by @filipnavara here:
dotnet/runtime#88032 (comment)

--- 
Fixes: #18552
  • Loading branch information
ivanpovazan authored Jul 13, 2023
1 parent 278b249 commit f212f6b
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion tools/dotnet-linker/Steps/ComputeNativeBuildFlagsStep.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;

using Xamarin.Utils;
using Xamarin.Bundler;

#nullable enable

Expand Down Expand Up @@ -51,7 +52,8 @@ protected override void TryEndProcess ()
Configuration.Application.DeadStrip = false;

var mainLinkerFlags = new List<MSBuildItem> ();
if (Configuration.Application.DeadStrip) {
// Do not pass -dead_strip to the native linker with object files generated by NativeAOT compiler as it can cause the linker to seg fault
if (Configuration.Application.DeadStrip && Configuration.Application.XamarinRuntime != XamarinRuntime.NativeAOT) {
mainLinkerFlags.Add (new MSBuildItem ("-dead_strip"));
}
Configuration.WriteOutputForMSBuild ("_AssemblyLinkerFlags", mainLinkerFlags);
Expand Down

6 comments on commit f212f6b

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

Please sign in to comment.