Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recognize AnyCPU in case of fallback to PEReader #3287

Merged
merged 9 commits into from
Jan 28, 2022
20 changes: 17 additions & 3 deletions src/vstest.console/CommandLine/AssemblyMetadataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,31 @@ private Architecture GetArchitectureFromAssemblyMetadata(string path)
switch (peReader.PEHeaders.CoffHeader.Machine)
{
case Machine.Amd64:
return Architecture.X64;
case Machine.IA64:
MarcoRossignoli marked this conversation as resolved.
Show resolved Hide resolved
return Architecture.X64;
case Machine.Arm64:
return Architecture.ARM64;
case Machine.Arm:
return Architecture.ARM;
case Machine.I386:
return Architecture.X86;
// We can distinguish AnyCPU only from the set of CorFlags.Requires32Bit, but in case of Ready
// to Run image that flag is not "updated" and ignored. So we check if the module is IL only or not.
// If it's not IL only it means that is a R2R (Ready to Run) and we're already in the correct architecture x86.
// In all other cases the architecture will end inside the correct switch branch.
var corflags = peReader.PEHeaders.CorHeader.Flags;
if ((corflags & CorFlags.Requires32Bit) != 0 || (corflags & CorFlags.ILOnly) == 0)
{
return Architecture.X86;
}
else
{
return Architecture.AnyCPU;
}
default:
break;
{
EqtTrace.Error($"AssemblyMetadataProvider.GetArchitecture: Unhandled architecture '{peReader.PEHeaders.CoffHeader.Machine}'.");
break;
}
}
}

Expand Down