Skip to content

Commit

Permalink
Expose stack trace metadata stripping as a supported option (#88235)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichalStrehovsky authored Jul 3, 2023
1 parent 779d536 commit f25bc7b
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ The .NET Foundation licenses this file to you under the MIT license.
<_IsApplePlatform Condition="'$(_targetOS)' == 'osx' or '$(_IsiOSLikePlatform)' == 'true'">true</_IsApplePlatform>
</PropertyGroup>

<!-- Set up the defaults for the compatibility mode -->
<PropertyGroup>
<IlcGenerateStackTraceData Condition="$(IlcGenerateStackTraceData) == ''">true</IlcGenerateStackTraceData>
<IlcScanReflection Condition="$(IlcScanReflection) == ''">true</IlcScanReflection>
</PropertyGroup>

<!-- Set up default feature switches -->
<PropertyGroup>
<UseSystemResourceKeys Condition="$(IlcDisableReflection) == 'true'">true</UseSystemResourceKeys>
Expand Down Expand Up @@ -104,7 +98,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="$(IlcGenerateStackTraceData) == 'true'" />
<AutoInitializedAssemblies Include="System.Private.StackTraceMetadata" Condition="$(StackTraceSupport) != 'false'" />
<AutoInitializedAssemblies Include="System.Private.TypeLoader" />
<AutoInitializedAssemblies Include="System.Private.Reflection.Execution" Condition="$(IlcDisableReflection) != 'true'" />
<AutoInitializedAssemblies Include="System.Private.DisabledReflection" Condition="$(IlcDisableReflection) == 'true'" />
Expand Down Expand Up @@ -249,8 +243,8 @@ The .NET Foundation licenses this file to you under the MIT license.
<IlcArg Include="--runtimeknob:RUNTIME_IDENTIFIER=$(RuntimeIdentifier)" />
<IlcArg Condition="$(ServerGarbageCollection) == 'true'" Include="--runtimeopt:gcServer=1" />
<IlcArg Condition="$(IlcGenerateCompleteTypeMetadata) == 'true' and $(IlcDisableReflection) != 'true'" Include="--completetypemetadata" />
<IlcArg Condition="$(IlcGenerateStackTraceData) == 'true'" Include="--stacktracedata" />
<IlcArg Condition="$(IlcScanReflection) == 'true' and $(IlcDisableReflection) != 'true'" Include="--scanreflection" />
<IlcArg Condition="$(StackTraceSupport) != 'false'" Include="--stacktracedata" />
<IlcArg Condition="$(IlcScanReflection) != 'false' and $(IlcDisableReflection) != 'true'" Include="--scanreflection" />
<IlcArg Condition="$(IlcFoldIdenticalMethodBodies) == 'true'" Include="--methodbodyfolding" />
<IlcArg Condition="$(Optimize) == 'true' and $(OptimizationPreference) == 'Size'" Include="--Os" />
<IlcArg Condition="$(Optimize) == 'true' and $(OptimizationPreference) == 'Speed'" Include="--Ot" />
Expand Down
4 changes: 0 additions & 4 deletions src/coreclr/nativeaot/docs/optimizing.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ Native AOT supports enabling and disabling all [documented framework library fea

Since `PublishTrimmed` is implied to be true with Native AOT, some framework features such as binary serialization are disabled by default.

## Options related to metadata generation

* `<IlcGenerateStackTraceData>false</IlcGenerateStackTraceData>`: this disables generation of stack trace metadata that provides textual names in stack traces. This is for example the text string one gets by calling `Exception.ToString()` on a caught exception. With this option disabled, stack traces will still be generated, but will be based on reflection metadata alone (they might be less complete).

## Options related to code generation
* `<OptimizationPreference>Speed</OptimizationPreference>`: when generating optimized code, favor code execution speed.
* `<OptimizationPreference>Size</OptimizationPreference>`: when generating optimized code, favor smaller code size.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Runtime.CompilerServices;

class Program
{
[MethodImpl(MethodImplOptions.NoInlining)]
static int Main()
{
string stackTrace = Environment.StackTrace;

Console.WriteLine(stackTrace);

#if STRIPPED
const bool expected = false;
#else
const bool expected = true;
#endif
bool actual = stackTrace.Contains(nameof(Main)) && stackTrace.Contains(nameof(Program));
return expected == actual ? 100 : 1;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<CLRTestKind>BuildAndRun</CLRTestKind>
<CLRTestPriority>0</CLRTestPriority>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<InvariantGlobalization>true</InvariantGlobalization>
<CLRTestTargetUnsupported Condition="'$(IlcMultiModule)' == 'true'">true</CLRTestTargetUnsupported>
</PropertyGroup>
<ItemGroup>
<Compile Include="StackTraceMetadata.cs" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<CLRTestKind>BuildAndRun</CLRTestKind>
<CLRTestPriority>0</CLRTestPriority>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<InvariantGlobalization>true</InvariantGlobalization>
<CLRTestTargetUnsupported Condition="'$(IlcMultiModule)' == 'true'">true</CLRTestTargetUnsupported>
<DefineConstants>$(DefineConstants);STRIPPED</DefineConstants>
<StackTraceSupport>false</StackTraceSupport>
</PropertyGroup>
<ItemGroup>
<Compile Include="StackTraceMetadata.cs" />
</ItemGroup>
</Project>

0 comments on commit f25bc7b

Please sign in to comment.