Skip to content

Commit

Permalink
Remove stack trace metadata decoding support if stack trace data disa…
Browse files Browse the repository at this point in the history
…bled (#88117)

We have an opt-in feature (currently not officially supported) to disable generation of stack trace metadata. This metadata is used to print the stack trace in places like `Exception.ToString`. This metadata is only generated for methods that are not visible reflection targets. If a method _is_ a visible reflection target, we obtain this data from reflection metadata. So currently it's possible for partial stack traces to be printed even if stack trace metadata was turned off.

I'm not sure it makes sense to do it this way now that very little surface area is actually visible from reflection. This PR conditions stack trace metadata decoding support on the same configuration option.

Before (with stack trace metadata disabled):

```
Unhandled Exception: System.Exception: Exception of type 'System.Exception' was thrown.
   at Program.<Main>$(String[] args) + 0x24
   at HelloBionic!<BaseAddress>+0x8a9e0
```

After:

```
Unhandled Exception: System.Exception: Exception of type 'System.Exception' was thrown.
   at HelloBionic!<BaseAddress>+0x4e958
   at HelloBionic!<BaseAddress>+0x85d5b
```

(Notice we had metadata for Main because we implicitly make `Assembly.EntryPoint` reflection visible. But if there was more code on stack, most of it would look like the "after" case.)

I think the new behavior is easier to comprehend.

This also shrinks the size of an app (with stack trace data disabled) that only throws an exception from 972,288 bytes to 945,152 bytes (the size of stack trace decoding support).

We should consider making this a supported option. It was a supported option in .NET Native and apps like the Windows Store actually ship like this.
  • Loading branch information
MichalStrehovsky authored Jun 28, 2023
1 parent 7575716 commit 293b250
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ The .NET Foundation licenses this file to you under the MIT license.
<ItemGroup Condition="$(IlcSystemModule) == ''">
<UnmanagedEntryPointsAssembly Include="System.Private.CoreLib" />
<AutoInitializedAssemblies Include="System.Private.CoreLib" />
<AutoInitializedAssemblies Include="System.Private.StackTraceMetadata" Condition="$(IlcDisableReflection) != 'true' or $(IlcGenerateStackTraceData) == 'true'" />
<AutoInitializedAssemblies Include="System.Private.StackTraceMetadata" Condition="$(IlcGenerateStackTraceData) == 'true'" />
<AutoInitializedAssemblies Include="System.Private.TypeLoader" />
<AutoInitializedAssemblies Include="System.Private.Reflection.Execution" Condition="$(IlcDisableReflection) != 'true'" />
<AutoInitializedAssemblies Include="System.Private.DisabledReflection" Condition="$(IlcDisableReflection) == 'true'" />
Expand Down

0 comments on commit 293b250

Please sign in to comment.