Make a copy of 'clrjit' binary for use in SuperPMI collect to avoid heap errors when...
authorWill Smith <lol.tihan@gmail.com>
Fri, 28 Jul 2023 08:23:31 +0000 (01:23 -0700)
committerGitHub <noreply@github.com>
Fri, 28 Jul 2023 08:23:31 +0000 (01:23 -0700)
* Make a copy of 'clrjit' binary for use in SuperPMI collect to avoid heap errors when the same 'clrjit' binary is used

* Feedback

* Feedback

src/coreclr/scripts/superpmi.py

index 78d7882..358a06c 100644 (file)
@@ -649,7 +649,18 @@ class SuperPMICollect:
 
         self.collection_shim_path = os.path.join(self.core_root, self.collection_shim_name)
 
-        self.jit_path = os.path.join(coreclr_args.core_root, get_jit_name(coreclr_args))
+        jit_name = get_jit_name(coreclr_args)
+        self.jit_path = os.path.join(coreclr_args.core_root, jit_name)
+        if coreclr_args.crossgen2:
+            # There are issues when running SuperPMI and crossgen2 when using the same JIT binary. 
+            # Therefore, we produce a copy of the JIT binary for SuperPMI to use. 
+            jit_name_ext = os.path.splitext(jit_name)[1]
+            jit_name_without_ext = os.path.splitext(jit_name)[0]
+            self.superpmi_jit_path = os.path.join(coreclr_args.core_root, jit_name_without_ext + "_superpmi." + jit_name_ext)
+            shutil.copyfile(self.jit_path, self.superpmi_jit_path)
+        else:
+            self.superpmi_jit_path = self.jit_path
+
         self.superpmi_path = determine_superpmi_tool_path(coreclr_args)
         self.mcs_path = determine_mcs_tool_path(coreclr_args)
 
@@ -774,6 +785,10 @@ class SuperPMICollect:
         if passed:
             logging.info("Generated MCH file: %s", self.final_mch_file)
 
+        # Cleanup the copy of the JIT binary.
+        if self.coreclr_args.crossgen2 and not self.coreclr_args.skip_cleanup:
+            os.remove(self.superpmi_jit_path)
+
         return passed
 
     ############################################################################
@@ -797,7 +812,7 @@ class SuperPMICollect:
 
             root_env = {}
             root_env["SuperPMIShimLogPath"] = self.temp_location
-            root_env["SuperPMIShimPath"] = self.jit_path
+            root_env["SuperPMIShimPath"] = self.superpmi_jit_path
 
             dotnet_env = {}
             dotnet_env["EnableExtraSuperPmiQueries"] = "1"