Skip to content

Commit

Permalink
Skip native composite ReadyToRun images as inputs to Crossgen2
Browse files Browse the repository at this point in the history
According to the issue #49247
a known pre-existing Crossgen2 bug is that it fails when presented
with the components of a previous Crossgen2 compilation in the
composite mode. This is because Crossgen2 lacks proper logic to
recognize the composite images and mistakes them for currently
unsupported managed C++ MSIL assemblies. This change adds the extra
check; I have also unified it between Crossgen2 and R2RDump.

Thanks

Tomas
  • Loading branch information
trylek committed Dec 9, 2021
1 parent 8ae1c49 commit 17b8ad1
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,16 @@ public static PEExportTable GetExportTable(this PEReader reader)
{
return PEExportTable.Parse(reader);
}

/// <summary>
/// Check whether the file is a ReadyToRun image and returns the RVA of its ReadyToRun header if positive.
/// </summary>
/// <param name="reader">PEReader representing the executable to check for the presence of ReadyToRun header</param>
/// <param name="rva">RVA of the ReadyToRun header if available, 0 when not</param>
/// <returns>true when the PEReader represents a ReadyToRun image, false otherwise</returns>
public static bool TryGetReadyToRunHeader(this PEReader reader, out int rva)
{
return reader.GetExportTable().TryGetValue("RTR_HEADER", out rva);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ public static bool IsReadyToRunImage(PEReader peReader)

if ((peReader.PEHeaders.CorHeader.Flags & CorFlags.ILLibrary) == 0)
{
return TryLocateNativeReadyToRunHeader(peReader, out _);
return peReader.TryGetReadyToRunHeader(out _);
}
else
{
Expand Down Expand Up @@ -565,16 +565,9 @@ public IReadOnlyDictionary<TMethod, ReadyToRunMethod> GetCustomMethodToRuntimeFu
return customMethods;
}

private static bool TryLocateNativeReadyToRunHeader(PEReader reader, out int readyToRunHeaderRVA)
{
PEExportTable exportTable = reader.GetExportTable();

return exportTable.TryGetValue("RTR_HEADER", out readyToRunHeaderRVA);
}

private bool TryLocateNativeReadyToRunHeader()
{
_composite = TryLocateNativeReadyToRunHeader(CompositeReader, out _readyToRunHeaderRVA);
_composite = CompositeReader.TryGetReadyToRunHeader(out _readyToRunHeaderRVA);

return _composite;
}
Expand Down
24 changes: 22 additions & 2 deletions src/coreclr/tools/aot/crossgen2.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29123.88
# Visual Studio Version 17
VisualStudioVersion = 17.0.31612.314
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "crossgen2", "crossgen2\crossgen2.csproj", "{9B928D3E-06AB-45E5-BF79-F374F0AE3B98}"
EndProject
Expand All @@ -14,6 +14,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ILCompiler.TypeSystem.Ready
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ILCompiler.Diagnostics", "ILCompiler.Diagnostics\ILCompiler.Diagnostics.csproj", "{3EACD929-4725-4173-A845-734936BBDF87}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ILCompiler.Reflection.ReadyToRun", "ILCompiler.Reflection.ReadyToRun\ILCompiler.Reflection.ReadyToRun.csproj", "{0BB34BA1-1B3A-445C-9C04-0D710D1983F0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Checked|Any CPU = Checked|Any CPU
Expand Down Expand Up @@ -122,6 +124,24 @@ Global
{3EACD929-4725-4173-A845-734936BBDF87}.Release|x64.Build.0 = Release|Any CPU
{3EACD929-4725-4173-A845-734936BBDF87}.Release|x86.ActiveCfg = Release|Any CPU
{3EACD929-4725-4173-A845-734936BBDF87}.Release|x86.Build.0 = Release|Any CPU
{0BB34BA1-1B3A-445C-9C04-0D710D1983F0}.Checked|Any CPU.ActiveCfg = Debug|Any CPU
{0BB34BA1-1B3A-445C-9C04-0D710D1983F0}.Checked|Any CPU.Build.0 = Debug|Any CPU
{0BB34BA1-1B3A-445C-9C04-0D710D1983F0}.Checked|x64.ActiveCfg = Debug|x64
{0BB34BA1-1B3A-445C-9C04-0D710D1983F0}.Checked|x64.Build.0 = Debug|x64
{0BB34BA1-1B3A-445C-9C04-0D710D1983F0}.Checked|x86.ActiveCfg = Debug|Any CPU
{0BB34BA1-1B3A-445C-9C04-0D710D1983F0}.Checked|x86.Build.0 = Debug|Any CPU
{0BB34BA1-1B3A-445C-9C04-0D710D1983F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0BB34BA1-1B3A-445C-9C04-0D710D1983F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0BB34BA1-1B3A-445C-9C04-0D710D1983F0}.Debug|x64.ActiveCfg = Debug|x64
{0BB34BA1-1B3A-445C-9C04-0D710D1983F0}.Debug|x64.Build.0 = Debug|x64
{0BB34BA1-1B3A-445C-9C04-0D710D1983F0}.Debug|x86.ActiveCfg = Debug|Any CPU
{0BB34BA1-1B3A-445C-9C04-0D710D1983F0}.Debug|x86.Build.0 = Debug|Any CPU
{0BB34BA1-1B3A-445C-9C04-0D710D1983F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0BB34BA1-1B3A-445C-9C04-0D710D1983F0}.Release|Any CPU.Build.0 = Release|Any CPU
{0BB34BA1-1B3A-445C-9C04-0D710D1983F0}.Release|x64.ActiveCfg = Release|x64
{0BB34BA1-1B3A-445C-9C04-0D710D1983F0}.Release|x64.Build.0 = Release|x64
{0BB34BA1-1B3A-445C-9C04-0D710D1983F0}.Release|x86.ActiveCfg = Release|Any CPU
{0BB34BA1-1B3A-445C-9C04-0D710D1983F0}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
7 changes: 7 additions & 0 deletions src/coreclr/tools/aot/crossgen2/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
using Internal.TypeSystem;
using Internal.TypeSystem.Ecma;

using ILCompiler.Reflection.ReadyToRun;

namespace ILCompiler
{
internal class Program
Expand Down Expand Up @@ -764,6 +766,11 @@ private void CheckManagedCppInputFiles(IEnumerable<string> inputPaths)
foreach (string inputFilePath in inputPaths)
{
EcmaModule module = _typeSystemContext.GetModuleFromPath(inputFilePath);
if (module.PEReader.TryGetReadyToRunHeader(out int _))
{
Console.WriteLine(SR.IgnoringCompositeImage, inputFilePath);
continue;
}
if ((module.PEReader.PEHeaders.CorHeader.Flags & (CorFlags.ILLibrary | CorFlags.ILOnly)) == (CorFlags)0)
{
throw new CommandLineException(string.Format(SR.ManagedCppNotSupported, inputFilePath));
Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/tools/aot/crossgen2/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,9 @@
<data name="ManagedCppNotSupported" xml:space="preserve">
<value>Error: managed C++ is not supported: '{0}'</value>
</data>
<data name="IgnoringCompositeImage" xml:space="preserve">
<value>Ignoring composite native image: '{0}'</value>
</data>
<data name="VerifyTypeAndFieldLayoutOption" xml:space="preserve">
<value>Verify that struct type layout and field offsets match between compile time and runtime. Use only for diagnostic purposes.</value>
</data>
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/tools/aot/crossgen2/crossgen2.props
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<ProjectReference Include="..\ILCompiler.DependencyAnalysisFramework\ILCompiler.DependencyAnalysisFramework.csproj" />
<ProjectReference Include="..\ILCompiler.TypeSystem.ReadyToRun\ILCompiler.TypeSystem.ReadyToRun.csproj" />
<ProjectReference Include="..\ILCompiler.ReadyToRun\ILCompiler.ReadyToRun.csproj" />
<ProjectReference Include="..\ILCompiler.Reflection.ReadyToRun\ILCompiler.Reflection.ReadyToRun.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 17b8ad1

Please sign in to comment.