Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

ARM64: Enable End-To-End ReadyToRun (R2R) Crossgen #5020

Merged
merged 1 commit into from
May 19, 2016

Conversation

kyulee1
Copy link

@kyulee1 kyulee1 commented May 17, 2016

Fixes https://github.com/dotnet/coreclr/issues/4649
The immediate issues was NYI on genEmitHelperCalls. The initial
implementation for the missing part was enough to just crossgen System.dll.
But running tests revealed various issues in crossgened binaries (R2R).
Most common user/helper calls in R2R are represented as indirect calls
similar to interface call using virtual stub dispatch cell --
thunk/helper needs a indirect cell address to update the final target
address on the data location. IsDelayLoadHelper and IsLazyHelper belong to
this case.
Instead of passing such parameter, x64/x86 uses an encoding trick -- it
assumes the call is dispatched like call [addr]. So from the return
address, runtime could extract indirect cell address. Unfortunately this is not
an option for arm64 (actually arm as well but I haven't fixed it in this
change) where indirect call on memory is not encodable.
So, I made the following changes:

  1. For the call requiring that needs to pass indirect cell address, I
    tagged the call tree via setR2RRelativeIndir. Tried to be comprehensive,
    but I may miss something. Currently, it includes a regular call and
    various helpers for (virtual) load function pointer/static data access, etc.
    Hopely we change JIT/EE interface somehow that gives us such explicit information.
  2. Use the X11 to record indirect cell address for such call tree in
    lower similar to VSD.
  3. Fixed encodings ZapIndirectHelperThunk. In particular the immediate
    value/offset for ldr should be scaled down 4 times since HW will scale
    it 4 times.
  4. Implement genEmitHelperCalls for indirect case. This is not the case requiring indirect
    cell address. This is the case we inlined the indirect helper thunk for
    the speed. I'm seeing the case for size opt helper call, we invoke a
    direct call to such thunk which actually uses x12 to dispatch the final
    target. Likewise, I used x12 for this expansion which seems a trash register that is not
    overlapped with arugments with jit helpers like writer barriers.

With this change, I've tested various cases/scenraios locally.
Also I've verified all tests are passed against mscorlib.ni.dll and System.ni.dll.

@kyulee1
Copy link
Author

kyulee1 commented May 17, 2016

@dotnet-bot test Windows_NT arm64 Checked

@kyulee1
Copy link
Author

kyulee1 commented May 17, 2016

@dotnet/arm64-contrib @dotnet/jit-contrib PTAL.
/cc @jkotas @JohnChen0.

@rahku
Copy link

rahku commented May 17, 2016

changes in zapimport look good to me

@briansull
Copy link

Looks Good

@@ -2870,6 +2871,15 @@ struct GenTreeCall final : public GenTree
bool IsSameThis() { return (gtCallMoreFlags & GTF_CALL_M_NONVIRT_SAME_THIS) != 0; }
bool IsDelegateInvoke(){ return (gtCallMoreFlags & GTF_CALL_M_DELEGATE_INV) != 0; }
bool IsVirtualStubRelativeIndir() { return (gtCallMoreFlags & GTF_CALL_M_VIRTSTUB_REL_INDIRECT) != 0; }
#ifdef FEATURE_READYTORUN_COMPILER

Choose a reason for hiding this comment

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

I don't believe that we want to have #ifdef's around this code.

@kyulee1 kyulee1 force-pushed the imp branch 2 times, most recently from 38df707 to c0ef1fe Compare May 18, 2016 21:21
Fixes https://github.com/dotnet/coreclr/issues/4649
The immediate issues was NYI on genEmitHelperCalls. The initial
implementation for the missing part was enough to just crossgen System.dll.
But running tests revealed various issues in crossgened binaries (R2R).
Most common user/helper calls in R2R are represented as indirect calls
similar to interface call using virtual stub dispatch cell --
thunk/helper needs a indirect cell address to update the final target
address on the data location. `IsDelayLoadHelper` and `IsLazyHelper` belong to
this case.
Instead of passing such parameter, x64/x86 uses an encoding trick -- it
assumes the call is dispatched like `call [addr]`. So from the return
address, runtime could extract indirect cell address. Unfortunately this is not
an option for arm64 (actually arm as well but I haven't fixed it in this
change) where indirect call on memory is not encodable.
So, I made the following changes:

1. For the call requiring that needs to pass indirect cell address, I
tagged the call tree via `setR2RRelativeIndir`. Tried to be comprehensive,
but I may miss something. Currently, it includes a regular call and
various helpers for (virtual) load function pointer/static data access, etc.
Hopely we change JIT/EE interface somehow that gives us such explicit information.

2. Use the X11 to record indirect cell address for such call tree in
lower similar to VSD.

3. Fixed encodings `ZapIndirectHelperThunk`. In particular the immediate
value/offset for `ldr` should be scaled down 4 times since HW will scale
it 4 times.

4. Implement `genEmitHelperCalls` for indirect case. This is not the case requiring indirect
cell address. This is the case we inlined the indirect helper thunk for
the speed. I'm seeing the case for size opt helper call, we invoke a
direct call to such thunk which actually uses x12 to dispatch the final
target. Likewise, I used x12 for this expansion which seems a trash register that is not
overlapped with arugments with jit helpers like writer barriers.

With this change, I've tested various cases/scenraios locally.
Also I've verified all tests are passed against mscorlib.ni.dll and System.ni.dll.
@kyulee1 kyulee1 merged commit 6f69c6d into dotnet:master May 19, 2016
@kyulee1 kyulee1 deleted the imp branch May 19, 2016 15:03
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
ARM64: Enable End-To-End ReadyToRun (R2R) Crossgen

Commit migrated from dotnet/coreclr@6f69c6d
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ARM64: InvalidProgramException is thrown when generating R2R images
5 participants