Skip to content

Commit 65f795b

Browse files
[NativeAOT-LLVM] Add a PNSE ThunkPool to the WASM build and prune out precise virtual unwind code (#3153)
* Add a wasmjit-diff 'base tag' feature Allows one to maintain multiple "bases" at once. * Remove PVI code from non-PVI builds * Add a ThunkPool PNSE implementation
1 parent 16c0e34 commit 65f795b

File tree

6 files changed

+67
-21
lines changed

6 files changed

+67
-21
lines changed

src/coreclr/nativeaot/Directory.Build.props

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,8 @@
7575

7676
<!-- Platform specific properties -->
7777
<PropertyGroup Condition="'$(Platform)' == 'wasm'">
78-
<!-- "WASM ABI" here refers to the use of shadow stacks, native-based EH, conservative GC, etc. -->
79-
<!-- It does not, in principle, imply TARGET_WASM, or vice-versa, though currently this is the case. -->
80-
<!-- In the future we may want to create a Windows/Unix build targeting this ABI, for testing. -->
81-
<WasmAbi>true</WasmAbi>
8278
<PlatformTarget>AnyCPU</PlatformTarget>
8379
<DefineConstants>TARGET_32BIT;TARGET_WASM;$(DefineConstants)</DefineConstants>
84-
<DefineConstants Condition="'$(TargetsBrowser)' == 'true'">TARGET_BROWSER;$(DefineConstants)</DefineConstants>
85-
<DefineConstants Condition="'$(TargetsWasi)' == 'true'">TARGET_WASI;$(DefineConstants)</DefineConstants>
8680
</PropertyGroup>
8781
<PropertyGroup Condition="'$(Platform)' == 'x64'">
8882
<DefineConstants>TARGET_64BIT;TARGET_AMD64;$(DefineConstants)</DefineConstants>
@@ -107,6 +101,8 @@
107101
<DefineConstants Condition="'$(TargetsWindows)'=='true'">TARGET_WINDOWS;$(DefineConstants)</DefineConstants>
108102
<DefineConstants Condition="'$(TargetsUnix)'=='true'">TARGET_UNIX;$(DefineConstants)</DefineConstants>
109103
<DefineConstants Condition="'$(TargetsBrowser)'=='true' or '$(TargetsWasi)'=='true'">TARGET_UNIX;$(DefineConstants)</DefineConstants>
104+
<DefineConstants Condition="'$(TargetsBrowser)'=='true'">TARGET_BROWSER;$(DefineConstants)</DefineConstants>
105+
<DefineConstants Condition="'$(TargetsWasi)'=='true'">TARGET_WASI;$(DefineConstants)</DefineConstants>
110106
</PropertyGroup>
111107

112108
<!-- Configuration specific properties -->

src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.wasm.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,11 @@ private static void HandleUnhandledException(object exception)
377377
[MethodImpl(MethodImplOptions.NoInlining)] // Ensures that the RhGetCurrentThreadStackTrace frame is always present
378378
private static unsafe int RhGetCurrentThreadStackTrace(IntPtr[] outputBuffer)
379379
{
380-
Debug.Assert(RuntimeAugments.PreciseVirtualUnwind);
380+
if (!RuntimeAugments.PreciseVirtualUnwind) // This helps to trim out the code below from !PreciseVirtualUnwind builds.
381+
{
382+
Debug.Fail("RhGetCurrentThreadStackTrace called with !PreciseVirtualUnwind");
383+
return 0;
384+
}
381385

382386
int count = 0;
383387
void* pFrameLimit = PreciseVirtualUnwindFrame.GetLimit();

src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<FeatureSharedLowLevelLock>true</FeatureSharedLowLevelLock>
4545
</PropertyGroup>
4646

47-
<PropertyGroup Condition="'$(WasmAbi)' == 'true'">
47+
<PropertyGroup Condition="'$(TargetsWasm)' == 'true'">
4848
<FeaturePortableGetUnboxingStubTarget>true</FeaturePortableGetUnboxingStubTarget>
4949
</PropertyGroup>
5050

@@ -212,7 +212,8 @@
212212
<Compile Include="System\Runtime\ExceptionIDs.cs" />
213213
<Compile Include="System\Runtime\GCSettings.NativeAot.cs" />
214214
<Compile Include="System\Runtime\TypeLoaderExports.cs" />
215-
<Compile Include="System\Runtime\ThunkPool.cs" />
215+
<Compile Include="System\Runtime\ThunkPool.cs" Condition="'$(TargetsWasm)' != 'true'" />
216+
<Compile Include="System\Runtime\ThunkPool.NotSupported.cs" Condition="'$(TargetsWasm)' == 'true'" />
216217
<Compile Include="System\Runtime\InitializeFinalizerThread.cs" />
217218
<Compile Include="System\Runtime\InteropServices\ComEventsHelper.NativeAot.cs" Condition="'$(FeatureCominterop)' == 'true'" />
218219
<Compile Include="System\Runtime\InteropServices\ComWrappers.NativeAot.cs" Condition="'$(FeatureComWrappers)' == 'true'" />
@@ -239,7 +240,7 @@
239240
<Compile Include="System\RuntimeExceptionHelpers.cs" />
240241
<Compile Include="System\EETypePtr.cs" />
241242
<Compile Include="System\Runtime\RuntimeImports.cs" />
242-
<Compile Include="System\Runtime\RuntimeImports.Wasm.cs" Condition="'$(WasmAbi)' == 'true'" />
243+
<Compile Include="System\Runtime\RuntimeImports.Wasm.cs" Condition="'$(TargetsWasm)' == 'true'" />
243244
<Compile Include="System\ModuleHandle.cs" />
244245
<Compile Include="System\RuntimeFieldHandle.cs" />
245246
<Compile Include="System\Text\StringBuilder.NativeAot.cs" />
@@ -593,16 +594,16 @@
593594
<Compile Include="$(RuntimeBasePath)System\Runtime\MethodTable.Runtime.cs">
594595
<Link>Runtime.Base\src\System\Runtime\MethodTable.Runtime.cs</Link>
595596
</Compile>
596-
<Compile Include="$(RuntimeBasePath)System\Runtime\ExceptionHandling.cs" Condition="'$(WasmAbi)' != 'true'">
597+
<Compile Include="$(RuntimeBasePath)System\Runtime\ExceptionHandling.cs" Condition="'$(TargetsWasm)' != 'true'">
597598
<Link>Runtime.Base\src\System\Runtime\ExceptionHandling.cs</Link>
598599
</Compile>
599-
<Compile Include="$(RuntimeBasePath)System\Runtime\ExceptionHandling.wasm.cs" Condition="'$(WasmAbi)' == 'true'">
600+
<Compile Include="$(RuntimeBasePath)System\Runtime\ExceptionHandling.wasm.cs" Condition="'$(TargetsWasm)' == 'true'">
600601
<Link>Runtime.Base\src\System\Runtime\ExceptionHandling.wasm.cs</Link>
601602
</Compile>
602603
<Compile Include="$(RuntimeBasePath)System\Runtime\InternalCalls.cs">
603604
<Link>Runtime.Base\src\System\Runtime\InternalCalls.cs</Link>
604605
</Compile>
605-
<Compile Include="$(RuntimeBasePath)System\Runtime\InternalCalls.Wasm.cs" Condition="'$(WasmAbi)' == 'true'">
606+
<Compile Include="$(RuntimeBasePath)System\Runtime\InternalCalls.Wasm.cs" Condition="'$(TargetsWasm)' == 'true'">
606607
<Link>Runtime.Base\src\System\Runtime\InternalCalls.Wasm.cs</Link>
607608
</Compile>
608609
<Compile Include="$(RuntimeBasePath)System\Runtime\RuntimeExports.cs">
@@ -622,8 +623,8 @@
622623
</Compile>
623624
</ItemGroup>
624625
<ItemGroup Condition="'$(InPlaceRuntime)' == 'true'">
625-
<Compile Include="$(IntermediatesDir)\nativeaot\Runtime\Full\AsmOffsets.cs" Condition="'$(WasmAbi)' != 'true'" />
626-
<Compile Include="$(IntermediatesDir.Replace('\ide', ''))\nativeaot\Runtime\Portable\AsmOffsetsPortable.cs" Condition="'$(WasmAbi)' == 'true'" /> <!-- its never in \ide\ -->
626+
<Compile Include="$(IntermediatesDir)\nativeaot\Runtime\Full\AsmOffsets.cs" Condition="'$(TargetsWasm)' != 'true'" />
627+
<Compile Include="$(IntermediatesDir.Replace('\ide', ''))\nativeaot\Runtime\Portable\AsmOffsetsPortable.cs" Condition="'$(TargetsWasm)' == 'true'" /> <!-- its never in \ide\ -->
627628
</ItemGroup>
628629

629630
<Import Project="$(LibrariesProjectRoot)\System.Private.CoreLib\src\System.Private.CoreLib.Shared.projitems" Label="Shared" />
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
//
5+
// WASM in general does not have support for dynamic code generation without access to the host.
6+
// Browser as a platform **does**, but we have so far decided to not support the APIs requiring
7+
// thunks there anyway, hence this stub implementaiton of the thunk pool.
8+
//
9+
#pragma warning disable CA1822 // Mark members as static
10+
11+
using Internal.Runtime.CompilerHelpers;
12+
13+
namespace System.Runtime
14+
{
15+
internal class ThunksHeap
16+
{
17+
public static unsafe ThunksHeap? CreateThunksHeap(IntPtr commonStubAddress)
18+
{
19+
throw new PlatformNotSupportedException();
20+
}
21+
22+
public unsafe IntPtr AllocateThunk()
23+
{
24+
throw new PlatformNotSupportedException();
25+
}
26+
27+
public unsafe void FreeThunk(IntPtr thunkAddress)
28+
{
29+
throw new PlatformNotSupportedException();
30+
}
31+
32+
public unsafe bool TryGetThunkData(IntPtr thunkAddress, out IntPtr context, out IntPtr target)
33+
{
34+
throw new PlatformNotSupportedException();
35+
}
36+
37+
public unsafe void SetThunkData(IntPtr thunkAddress, IntPtr context, IntPtr target)
38+
{
39+
throw new PlatformNotSupportedException();
40+
}
41+
}
42+
}

src/coreclr/nativeaot/Test.CoreLib/src/Test.CoreLib.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
<Compile Include="..\..\Runtime.Base\src\System\Runtime\InternalCalls.cs">
5757
<Link>Runtime.Base\src\System\Runtime\InternalCalls.cs</Link>
5858
</Compile>
59-
<Compile Include="..\..\Runtime.Base\src\System\Runtime\InternalCalls.Wasm.cs" Condition="'$(WasmAbi)' == 'true'">
59+
<Compile Include="..\..\Runtime.Base\src\System\Runtime\InternalCalls.Wasm.cs" Condition="'$(TargetsWasm)' == 'true'">
6060
<Link>Runtime.Base\src\System\Runtime\InternalCalls.Wasm.cs</Link>
6161
</Compile>
6262
<Compile Include="..\..\Runtime.Base\src\System\Runtime\RuntimeExports.cs">
@@ -79,8 +79,8 @@
7979
</Compile>
8080
</ItemGroup>
8181
<ItemGroup Condition="'$(InPlaceRuntime)' == 'true'">
82-
<Compile Include="$(IntermediatesDir)\nativeaot\Runtime\Full\AsmOffsets.cs" Condition="'$(WasmAbi)' != 'true'"/>
83-
<Compile Include="$(IntermediatesDir.Replace('\ide', ''))\nativeaot\Runtime\Portable\AsmOffsetsPortable.cs" Condition="'$(WasmAbi)' == 'true'"/> <!-- its never in \ide\ -->
82+
<Compile Include="$(IntermediatesDir)\nativeaot\Runtime\Full\AsmOffsets.cs" Condition="'$(TargetsWasm)' != 'true'"/>
83+
<Compile Include="$(IntermediatesDir.Replace('\ide', ''))\nativeaot\Runtime\Portable\AsmOffsetsPortable.cs" Condition="'$(TargetsWasm)' == 'true'"/> <!-- its never in \ide\ -->
8484
</ItemGroup>
8585
<ItemGroup>
8686
<Compile Include="$(CompilerCommonPath)\Internal\NativeFormat\NativeFormatReader.Primitives.cs">

src/tests/nativeaot/SmokeTests/HelloWasm/wasmjit-diff.ps1

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
Param(
88
[Parameter(Position=0)]$TestProject = "HelloWasm.csproj",
99
[ValidateSet("browser","wasi")][string]$OS = "browser",
10-
[switch]$Build,
10+
[switch][Alias("b")]$Build,
1111
[switch]$Rebuild,
1212
[switch]$Analyze,
1313
[switch]$Summary,
1414
[switch]$Llvm,
1515
[ValidateSet("Debug","Checked","Release")][string]$Config = "Release",
1616
[ValidateSet("Debug","Checked","Release")][string]$IlcConfig = "Release",
17+
[string][Alias("bt")]$BaseTag = "",
1718
[Nullable[bool]]$DebugSymbols = $null,
1819
[uint]$NumberOfDiffsToShow = 20,
1920
[string]$PassThrough = ""
@@ -40,6 +41,7 @@ if ($ShowHelp)
4041
Write-Host " -Llvm : Analyze LLVM bitcode output instead of WASM"
4142
Write-Host " -Config : Test configuration (Debug/Release). Default is Release"
4243
Write-Host " -IlcConfig : ILC configuration (Debug/Checked/Release). Default is Release"
44+
Write-Host " -BaseTag : Suffix to use for the 'base' directory. Default is none"
4345
Write-Host " -DebugSymbols : Whether to build with debug symbols. Default is yes"
4446
Write-Host " -NumberOfDiffsToShow : Number of diffs to show. Default is 20"
4547
Write-Host " -PassThrough : Additional command line to pass directly to 'dotnet'"
@@ -82,10 +84,11 @@ $TestProjectDirectory = [IO.Path]::GetDirectoryName($TestProjectPath)
8284
$RuntimeTestsDirectory = "$RuntimelabDirectory/src/tests"
8385
$TestProjectDirectoryRelativePath = [System.IO.Path]::GetRelativePath($RuntimeTestsDirectory, $TestProjectDirectory)
8486

87+
$FullBaseTag = $BaseTag ? "base.$BaseTag" : "base"
8588
$TestProjectNativeObjDirectory = "$RuntimelabDirectory/artifacts/tests/coreclr/obj/$OS.$Arch.$Config/Managed/$TestProjectDirectoryRelativePath/$TestProjectName/native"
86-
$TestProjectBaseNativeObjDirectory = "$TestProjectNativeObjDirectory.base"
89+
$TestProjectBaseNativeObjDirectory = "$TestProjectNativeObjDirectory.$FullBaseTag"
8790
$TestProjectNativeOutputDirectory = "$RuntimelabDirectory/artifacts/tests/coreclr/$OS.$Arch.$Config/$TestProjectDirectoryRelativePath/$TestProjectName/native"
88-
$TestProjectBaseNativeOutputDirectory = "$TestProjectNativeOutputDirectory.base"
91+
$TestProjectBaseNativeOutputDirectory = "$TestProjectNativeOutputDirectory.$FullBaseTag"
8992
$TestProjectWasmOutput = "$TestProjectNativeOutputDirectory/$TestProjectName.wasm"
9093
$TestProjectBaseWasmOutput = "$TestProjectBaseNativeOutputDirectory/$TestProjectName.wasm"
9194

0 commit comments

Comments
 (0)