Skip to content
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

[SuperPMI] Support spmi-asmdiffs on Arm64 #48683

Merged
merged 28 commits into from
Feb 26, 2021

Conversation

echesakov
Copy link
Contributor

@echesakov echesakov commented Feb 24, 2021

  1. Convert #ifdef TARGET_* in CompileResult::applyRelocs in compileresult.cpp to runtime checks and allow SuperPMI to work with cross-architecture jits during asmdiffs (e.g. clrjit_win_arm64_x64.dll)
  2. Refactor CompileResult::applyRelocs and separate platform specific relocations (x86, arm64, 64-bit targets) from platform agnostic relocations
  3. Support IMAGE_REL_ARM64_BRANCH26, IMAGE_REL_ARM64_PAGEBASE_REL21 and IMAGE_REL_ARM64_PAGEOFFSET_12A in CompileResult::applyRelocs.
  4. Support IMAGE_REL_BASED_THUMB_MOV32, IMAGE_REL_BASED_REL_THUMB_MOV32_PCREL and IMAGE_REL_BASED_THUMB_BRANCH24 in CompileResult::applyRelocs.
  5. Adjust code section size that SuperPMI gets by calling repAllocMem in NearDiffer::compare in neardiffer.cpp. On Arm64 methods that have literal (constant) pools will fail decoding since the pools are appended to the methods code section and the size of code section reported by repAllocMem will include the constant pool. In order to avoid decoding of the constant pools and adjust code section to only contain executable portion - use repCompileMethod in NearDiffer::compare.

… and move them to src/coreclr/ToolBox/superpmi/superpmi-shared
…ompileResult::applyRelocs in src/coreclr/ToolBox/superpmi/superpmi-shared/compileresult.cpp
…r/ToolBox/superpmi/superpmi-shared/compileresult.cpp
…n src/coreclr/ToolBox/superpmi/superpmi-shared/compileresult.cpp
…red/spmiutil.cpp src/coreclr/ToolBox/superpmi/superpmi-shared/spmiutil.h
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Feb 24, 2021
@echesakov echesakov changed the title [SuperPMI] Add support for Arm64 [SuperPMI] Support spmi-asmdiffs on Arm64 Feb 24, 2021
…perpmi/superpmi-shared/spmiutil.cpp src/coreclr/ToolBox/superpmi/superpmi-shared/spmiutil.h
…AGEBASE_REL21 and IMAGE_REL_ARM64_PAGEOFFSET_12A in compileresult.cpp
…x/superpmi/superpmi-shared/spmiutil.cpp src/coreclr/ToolBox/superpmi/superpmi-shared/spmiutil.h
…_PCREL IMAGE_REL_BASED_THUMB_BRANCH24 on Arm in compileresult.cpp
if ((section_begin <= address) && (address < section_end)) // A reloc for our section?
{
if (!FitsInThumb2BlRel24(delta))
{
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was not sure what to do here. IIRC, if such overflow occurs in real product during crossgen the JIT would be required to re-compile the method without using this type of relocation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BruceForstall Any opinion if this is desired behavior? What would/should happen during spmi collect when such relocation overflow occurs? Would the corresponding method context be included in the final collection?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what would happen during spmi collection if it failed. It's supposed to throw and retry, but the retry logic for relocs in crossgen1 seems to be dependent on m_fNGenLastRetry, but I can't find how that ever gets set to true (because it's dependent on fNgenLastRetry, which is never set to true).

It looks like crossgen2 always returns IMAGE_REL_BASED_THUMB_BRANCH24 with no provision for overflow.

I would guess spmi would only record the retry compilation, but it's not clear that ever happens.

@echesakov echesakov marked this pull request as ready for review February 25, 2021 21:59
@echesakov
Copy link
Contributor Author

With this change I could successfully run spmi-asmdiffs on

  • win-x64 host using clrjit_win_arm64_x64.dll with the latest win-arm64 mch collections
  • win-x86 host using clrjit_unix_arm_x86.dll with the latest linux-arm mch collections

No errors due to "Unknown reloc type" or "Decoding has failed"

Note that I had to remove this line that was setting JitRequired=1 during superpmi.py asmdiffs (but not during replay). Otherwise, spmi-asmdiffs would trigger assertions in the JIT due to BADCODE while replaying some of the tests (e.g. JIT\Directed\coverage\importer\Desktop\badldsfld_il_r). After discussion this with Bruce - we came to conclusion that the line should be removed from the script.

@BruceForstall @dotnet/jit-contrib PTAL

Copy link
Member

@BruceForstall BruceForstall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a couple other TARGET ifdefs it seems like you could address while you're at it:

TypeUtils::GetCorInfoTypeName() // simple output code
CallUtils::HasRetBuffArg() // unreferenced; can just be deleted

Copy link
Member

@BruceForstall BruceForstall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for finding the sizeof() cases. I'm sure we'll find more cross-target issues over time, but this is a good update.

if ((section_begin <= address) && (address < section_end)) // A reloc for our section?
{
if (!FitsInThumb2BlRel24(delta))
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what would happen during spmi collection if it failed. It's supposed to throw and retry, but the retry logic for relocs in crossgen1 seems to be dependent on m_fNGenLastRetry, but I can't find how that ever gets set to true (because it's dependent on fNgenLastRetry, which is never set to true).

It looks like crossgen2 always returns IMAGE_REL_BASED_THUMB_BRANCH24 with no provision for overflow.

I would guess spmi would only record the retry compilation, but it's not clear that ever happens.

@ghost
Copy link

ghost commented Feb 26, 2021

Hello @echesakovMSFT!

Because this pull request has the auto-merge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@echesakov
Copy link
Contributor Author

The failure in runtime (CoreCLR Pri0 Runtime Tests Run windows arm64 checked) is not relevant

D:\h\w\B2C309DA\w\A26B08C8\e>dotnet D:\h\w\B2C309DA\p\xunit\xunit.console.dll JIT\HardwareIntrinsics\JIT.HardwareIntrinsics.XUnitWrapper.dll -parallel collections -nocolor -noshadow -xml testResults.xml -trait TestGroup=JIT.HardwareIntrinsics 
Microsoft.DotNet.XUnitConsoleRunner v2.5.0 (64-bit .NET 5.0.0)
System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

tracked by #48820

@echesakov echesakov merged commit b767622 into dotnet:master Feb 26, 2021
@echesakov echesakov deleted the SuperPMI-Arm64 branch February 26, 2021 22:40
@ghost ghost locked as resolved and limited conversation to collaborators Mar 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-arm32 arch-arm64 area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants