From 6b6823b1129327a4419b8c62dc800d4205eb6de0 Mon Sep 17 00:00:00 2001 From: Gleb Balykov Date: Thu, 2 Sep 2021 01:08:02 +0300 Subject: [PATCH] Use temporary ni.dll.tmp files with crossgen2 pipeline mode in order to not interfere with crossgen2 itself (#57341) * Use temporary ni.dll.tmp files with crossgen2 pipeline mode in order to not interfere with crossgen2 itself * Add check that --single-file-compilation mode of crossgen2 is always used with --out-near-input --- src/coreclr/tools/aot/crossgen2/Program.cs | 19 ++++++++++++++++++- .../tools/aot/crossgen2/Properties/Resources.resx | 6 ++++++ src/coreclr/tools/r2rtest/Buckets.cs | 1 + 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/coreclr/tools/aot/crossgen2/Program.cs b/src/coreclr/tools/aot/crossgen2/Program.cs index e9eb592..4e29497 100644 --- a/src/coreclr/tools/aot/crossgen2/Program.cs +++ b/src/coreclr/tools/aot/crossgen2/Program.cs @@ -326,6 +326,9 @@ namespace ILCompiler if (_commandLineOptions.OutputFilePath == null && !_commandLineOptions.OutNearInput) throw new CommandLineException(SR.MissingOutputFile); + if (_commandLineOptions.SingleFileCompilation && !_commandLineOptions.OutNearInput) + throw new CommandLineException(SR.MissingOutNearInput); + ConfigureTarget(); InstructionSetSupport instructionSetSupport = ConfigureInstructionSetSupport(); @@ -500,6 +503,19 @@ namespace ILCompiler RunSingleCompilation(singleCompilationInputFilePaths, instructionSetSupport, compositeRootPath, unrootedInputFilePaths, singleCompilationVersionBubbleModulesHash, typeSystemContext); } + + // In case of inputbubble ni.dll are created as ni.dll.tmp in order to not interfere with crossgen2, move them all to ni.dll + // See https://github.com/dotnet/runtime/issues/55663#issuecomment-898161751 for more details + if (_commandLineOptions.InputBubble) + { + foreach (var inputFile in inputFilePaths) + { + var tmpOutFile = inputFile.Value.Replace(".dll", ".ni.dll.tmp"); + var outFile = inputFile.Value.Replace(".dll", ".ni.dll"); + Console.WriteLine($@"Moving R2R PE file: {tmpOutFile} to {outFile}"); + System.IO.File.Move(tmpOutFile, outFile); + } + } } else { @@ -514,7 +530,8 @@ namespace ILCompiler // // Initialize output filename // - var outFile = _commandLineOptions.OutNearInput ? inFilePaths.First().Value.Replace(".dll", ".ni.dll") : _commandLineOptions.OutputFilePath; + var suffixStr = _commandLineOptions.SingleFileCompilation && _commandLineOptions.InputBubble ? ".ni.dll.tmp" : ".ni.dll"; + var outFile = _commandLineOptions.OutNearInput ? inFilePaths.First().Value.Replace(".dll", suffixStr) : _commandLineOptions.OutputFilePath; using (PerfEventSource.StartStopEvents.CompilationEvents()) { diff --git a/src/coreclr/tools/aot/crossgen2/Properties/Resources.resx b/src/coreclr/tools/aot/crossgen2/Properties/Resources.resx index 85ba1a7..0514c35 100644 --- a/src/coreclr/tools/aot/crossgen2/Properties/Resources.resx +++ b/src/coreclr/tools/aot/crossgen2/Properties/Resources.resx @@ -132,6 +132,9 @@ Emitting R2R PE file: {0} + + Moving R2R PE file: {0} to {1} + Enable optimizations @@ -192,6 +195,9 @@ Output filename must be specified (--out <file>) + + Single file compilation mode requires --out-near-input option + No input files are loadable diff --git a/src/coreclr/tools/r2rtest/Buckets.cs b/src/coreclr/tools/r2rtest/Buckets.cs index 387d753..927182e 100644 --- a/src/coreclr/tools/r2rtest/Buckets.cs +++ b/src/coreclr/tools/r2rtest/Buckets.cs @@ -112,6 +112,7 @@ namespace R2RTest line.StartsWith("EXEC : warning") || line.StartsWith("To repro,") || line.StartsWith("Emitting R2R PE file") || + line.StartsWith("Moving R2R PE file") || line.StartsWith("Warning: ") || line.StartsWith("Info: ") || line == "Assertion Failed") -- 2.7.4