Expose stack trace metadata stripping as a supported option (#88235)
authorMichal Strehovský <MichalStrehovsky@users.noreply.github.com>
Mon, 3 Jul 2023 04:08:33 +0000 (13:08 +0900)
committerGitHub <noreply@github.com>
Mon, 3 Jul 2023 04:08:33 +0000 (13:08 +0900)
src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets
src/coreclr/nativeaot/docs/optimizing.md
src/tests/nativeaot/SmokeTests/StackTraceMetadata/StackTraceMetadata.cs [new file with mode: 0644]
src/tests/nativeaot/SmokeTests/StackTraceMetadata/StackTraceMetadata.csproj [new file with mode: 0644]
src/tests/nativeaot/SmokeTests/StackTraceMetadata/StackTraceMetadata_Stripped.csproj [new file with mode: 0644]

index 0969d7f..3b40c7a 100644 (file)
@@ -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>
@@ -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'" />
@@ -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" />
index 9a90eb9..05ffe17 100644 (file)
@@ -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.
diff --git a/src/tests/nativeaot/SmokeTests/StackTraceMetadata/StackTraceMetadata.cs b/src/tests/nativeaot/SmokeTests/StackTraceMetadata/StackTraceMetadata.cs
new file mode 100644 (file)
index 0000000..19bff10
--- /dev/null
@@ -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;
+    }
+
+}
diff --git a/src/tests/nativeaot/SmokeTests/StackTraceMetadata/StackTraceMetadata.csproj b/src/tests/nativeaot/SmokeTests/StackTraceMetadata/StackTraceMetadata.csproj
new file mode 100644 (file)
index 0000000..e53e615
--- /dev/null
@@ -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>
diff --git a/src/tests/nativeaot/SmokeTests/StackTraceMetadata/StackTraceMetadata_Stripped.csproj b/src/tests/nativeaot/SmokeTests/StackTraceMetadata/StackTraceMetadata_Stripped.csproj
new file mode 100644 (file)
index 0000000..76478d8
--- /dev/null
@@ -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>