Repository navigation
[RISC-V] Fix jump stubs and emit direct calls PC-relative #135610
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pcshrosbree
wants to merge
4
commits into
dotnet:main
Choose a base branch
from
pcshrosbree:fix/riscv64-jump-stubs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+120
−48
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
06c3446
[RISC-V] Use the jump stub that recordRelocation allocates, and keep …
pcshrosbree 9d2a4ee
[RISC-V] Always emit direct calls PC-relative and let the VM insert j…
pcshrosbree d1f23c5
[RISC-V] Add a jump stub test that runs under DOTNET_ForceRelocs
pcshrosbree 80d2714
[RISC-V] Count every out-of-range call toward the jump stub reserve
pcshrosbree File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| // Runs four call shapes with DOTNET_ForceRelocs=1. On RISC-V, where W^X is off by default, Checked and Debug | ||
| // runtimes then reserve executable memory at scattered addresses, which can put helper and cross-heap targets | ||
| // out of auipc + jalr range, so that those calls go through jump stubs. | ||
|
|
||
| using System; | ||
| using System.Runtime.CompilerServices; | ||
| using Xunit; | ||
|
|
||
| public static class ForceRelocsJumpStubs | ||
| { | ||
| private sealed class Holder | ||
| { | ||
| public object Field; | ||
| } | ||
|
|
||
| [Fact] | ||
| public static void TestEntryPoint() | ||
| { | ||
| var holder = new Holder(); | ||
| Assert.Same(StoreNew(holder), holder.Field); | ||
| Assert.Equal("jumpstub", Concat("jump", "stub")); | ||
| Assert.Equal(42, CatchFromThrower()); | ||
| Assert.Equal(7, Add(3, 4)); | ||
| } | ||
|
|
||
| // Allocation and write-barrier helpers. | ||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| private static object StoreNew(Holder holder) => holder.Field = new object(); | ||
|
|
||
| // A call into CoreLib. | ||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| private static string Concat(string a, string b) => string.Concat(a, b); | ||
|
|
||
| // The throw helper, and an unwind back through the caller. | ||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| private static int CatchFromThrower() | ||
| { | ||
| try | ||
| { | ||
| Thrower(); | ||
| return -1; | ||
| } | ||
| catch (InvalidOperationException) | ||
| { | ||
| return 42; | ||
| } | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| private static void Thrower() => throw new InvalidOperationException(); | ||
|
|
||
| // A plain managed call with a return value. | ||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| private static int Add(int a, int b) => a + b; | ||
| } |
17 changes: 17 additions & 0 deletions
17
src/tests/baseservices/jumpstubs/ForceRelocsJumpStubs.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <!-- Needed for CLRTestEnvironmentVariable --> | ||
| <RequiresProcessIsolation>true</RequiresProcessIsolation> | ||
| <Optimize>true</Optimize> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <Compile Include="ForceRelocsJumpStubs.cs" /> | ||
|
|
||
| <!-- Read by Checked and Debug runtimes only. On RISC-V, where W^X is off by default, it also scatters | ||
| executable memory, which can put helper and cross-heap targets out of range so that those calls go | ||
| through jump stubs; elsewhere this is an ordinary ForceRelocs run. --> | ||
| <CLRTestEnvironmentVariable Include="DOTNET_ForceRelocs" Value="1" /> | ||
| <!-- Optimized code from the start, so that the call shapes under test are the optimized ones. --> | ||
| <CLRTestEnvironmentVariable Include="DOTNET_TieredCompilation" Value="0" /> | ||
| </ItemGroup> | ||
| </Project> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.