Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/coreclr/vm/peimagelayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,18 @@ PEImageLayout* PEImageLayout::LoadConverted(PEImage* pOwner)
// ConvertedImageLayout may be able to handle them, but the fact that we were unable to
// load directly implies that MAPMapPEFile could not consume what crossgen produced.
// that is suspicious, one or another might have a bug.
_ASSERTE(!pFlat->HasReadyToRunHeader());
_ASSERTE(!pOwner->IsFile() || !pFlat->HasReadyToRunHeader());
#endif

if (!pFlat->HasReadyToRunHeader() && !pFlat->HasWriteableSections())
// ignore R2R if the image is not a file.
if ((pFlat->HasReadyToRunHeader() && pOwner->IsFile()) ||
pFlat->HasWriteableSections())
{
// we can use flat layout for this
return pFlat.Extract();
return new ConvertedImageLayout(pFlat);
}

return new ConvertedImageLayout(pFlat);
// we can use flat layout for this
return pFlat.Extract();
}

PEImageLayout* PEImageLayout::Load(PEImage* pOwner, HRESULT* loadFailure)
Expand Down Expand Up @@ -448,7 +450,7 @@ ConvertedImageLayout::ConvertedImageLayout(FlatImageLayout* source)

IfFailThrow(Init(loadedImage));

if (IsNativeMachineFormat() && g_fAllowNativeImages)
if (m_pOwner->IsFile() && IsNativeMachineFormat() && g_fAllowNativeImages)
{
// Do base relocation and exception hookup, if necessary.
// otherwise R2R will be disabled for this image.
Expand Down
14 changes: 11 additions & 3 deletions src/tests/readytorun/tests/main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,13 @@ static void RVAFieldTest()
Assert.AreEqual(value[i], (byte)(9 - i));
}

// public constructor, so we run something when loading from byte array in the test below
public Program()
{
// do something in the constructor to see if it works
TestVirtualMethodCalls();
}

static void TestLoadR2RImageFromByteArray()
{
Assembly assembly1 = typeof(Program).Assembly;
Expand All @@ -422,6 +429,8 @@ static void TestLoadR2RImageFromByteArray()
Assembly assembly2 = Assembly.Load(array);

Assert.AreEqual(assembly2.FullName, assembly1.FullName);

assembly2.CreateInstance("Program");
}

[MethodImplAttribute(MethodImplOptions.NoInlining)]
Expand Down Expand Up @@ -513,9 +522,8 @@ static void RunAllTests()
Console.WriteLine("RVAFieldTest");
RVAFieldTest();

// Disable for https://github.com/dotnet/runtime/issues/71507
// Console.WriteLine("TestLoadR2RImageFromByteArray");
// TestLoadR2RImageFromByteArray();
Console.WriteLine("TestLoadR2RImageFromByteArray");
TestLoadR2RImageFromByteArray();

Console.WriteLine("TestILBodyChange");
TestILBodyChange();
Expand Down