Skip to content

Commit 77115c3

Browse files
authored
Allow R2R for images provided via external_assembly_probe (#112934)
Allow R2R for images provided via `external_assembly_probe` This re-uses the existing mechanism from single-file with R2R, where we load the image by copying it. This is obviously inefficient, but allows a first version of functioning R2R for Android.
1 parent 949ad0f commit 77115c3

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/coreclr/vm/peimagelayout.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@ extern "C"
1919
}
2020
#endif
2121

22+
static bool AllowR2RForImage(PEImage* pOwner)
23+
{
24+
// Allow R2R for files
25+
if (pOwner->IsFile())
26+
return true;
27+
28+
// Allow R2R for externally provided images
29+
INT64 size;
30+
if (pOwner->GetExternalData(&size) != NULL && size > 0)
31+
return true;
32+
33+
return false;
34+
}
35+
2236
#ifndef DACCESS_COMPILE
2337
PEImageLayout* PEImageLayout::CreateFromByteArray(PEImage* pOwner, const BYTE* array, COUNT_T size)
2438
{
@@ -70,9 +84,11 @@ PEImageLayout* PEImageLayout::LoadConverted(PEImage* pOwner, bool disableMapping
7084
pFlat = (FlatImageLayout*)pOwner->GetFlatLayout();
7185
pFlat->AddRef();
7286
}
73-
else if (pOwner->IsFile())
87+
else if (AllowR2RForImage(pOwner))
7488
{
89+
// We only expect to be converting images that aren't already opened in the R2R composite case
7590
pFlat = new FlatImageLayout(pOwner);
91+
_ASSERTE(pFlat->HasReadyToRunHeader());
7692
}
7793

7894
if (pFlat == NULL || !pFlat->CheckILOnlyFormat())
@@ -88,9 +104,8 @@ PEImageLayout* PEImageLayout::LoadConverted(PEImage* pOwner, bool disableMapping
88104
_ASSERTE(!pOwner->IsFile() || !pFlat->HasReadyToRunHeader() || disableMapping);
89105
#endif
90106

91-
// ignore R2R if the image is not a file.
92-
if ((pFlat->HasReadyToRunHeader() && pOwner->IsFile()) ||
93-
pFlat->HasWriteableSections())
107+
if ((pFlat->HasReadyToRunHeader() && AllowR2RForImage(pOwner))
108+
|| pFlat->HasWriteableSections())
94109
{
95110
return new ConvertedImageLayout(pFlat, disableMapping);
96111
}
@@ -462,7 +477,7 @@ ConvertedImageLayout::ConvertedImageLayout(FlatImageLayout* source, bool disable
462477

463478
IfFailThrow(Init(loadedImage));
464479

465-
if (m_pOwner->IsFile() && IsNativeMachineFormat())
480+
if (AllowR2RForImage(m_pOwner) && IsNativeMachineFormat())
466481
{
467482
// Do base relocation and exception hookup, if necessary.
468483
// otherwise R2R will be disabled for this image.

0 commit comments

Comments
 (0)