Don't do STRESS_PROFILER_CALLBACKS when pre-JITing (#2016)
authorBruce Forstall <brucefo@microsoft.com>
Wed, 22 Jan 2020 20:48:33 +0000 (12:48 -0800)
committerGitHub <noreply@github.com>
Wed, 22 Jan 2020 20:48:33 +0000 (12:48 -0800)
This leads us to generate an illegal relocation fixup.

Fixes #1789

src/coreclr/src/jit/compiler.cpp

index 0029094..a3b8c9c 100644 (file)
@@ -3092,10 +3092,16 @@ void Compiler::compInitOptions(JitFlags* jitFlags)
     // Honour COMPlus_JitELTHookEnabled or STRESS_PROFILER_CALLBACKS stress mode
     // only if VM has not asked us to generate profiler hooks in the first place.
     // That is, override VM only if it hasn't asked for a profiler callback for this method.
-    if (!compProfilerHookNeeded &&
-        ((JitConfig.JitELTHookEnabled() != 0) || compStressCompile(STRESS_PROFILER_CALLBACKS, 5)))
+    // Don't run this stress mode when pre-JITing, as we would need to emit a relocation
+    // for the call to the fake ELT hook, which wouldn't make sense, as we can't store that
+    // in the pre-JIT image.
+    if (!compProfilerHookNeeded)
     {
-        opts.compJitELTHookEnabled = true;
+        if ((JitConfig.JitELTHookEnabled() != 0) ||
+            (!jitFlags->IsSet(JitFlags::JIT_FLAG_PREJIT) && compStressCompile(STRESS_PROFILER_CALLBACKS, 5)))
+        {
+            opts.compJitELTHookEnabled = true;
+        }
     }
 
     // TBD: Exclude PInvoke stubs