[RyuJIT] Fix rel32 for calls/data (#49549)
authorEgor Bogatov <egorbo@gmail.com>
Mon, 15 Mar 2021 12:24:57 +0000 (15:24 +0300)
committerGitHub <noreply@github.com>
Mon, 15 Mar 2021 12:24:57 +0000 (15:24 +0300)
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
src/coreclr/jit/lower.cpp

index 6641f41..0316856 100644 (file)
@@ -4503,7 +4503,12 @@ GenTree* Lowering::LowerNonvirtPinvokeCall(GenTreeCall* call)
         switch (lookup.accessType)
         {
             case IAT_VALUE:
-                if (!IsCallTargetInRange(addr))
+                // IsCallTargetInRange always return true on x64. It wants to use rip-based addressing
+                // for this call. Unfortunately, in case of pinvokes (+suppressgctransition) to external libs
+                // (e.g. kernel32.dll) the relative offset is unlikely to fit into int32 and we will have to
+                // turn fAllowRel32 off globally.
+                if ((call->IsSuppressGCTransition() && !comp->opts.jitFlags->IsSet(JitFlags::JIT_FLAG_PREJIT)) ||
+                    !IsCallTargetInRange(addr))
                 {
                     result = AddrGen(addr);
                 }