From 77d4c11fcd67414d2195a63287e9c8e0b6f32958 Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Mon, 19 Mar 2018 20:23:39 -0700 Subject: Use flat layout for GetAssemblyName (#17052) * Use flat layout for GetAssemblyName This change will result in the use flat layouts for the temporary layouts created by GetAssemblyName. This allows crossgen'd PE images created for a different OS to be loaded in the code path that retrieves the assembly name. * Respond to PR feedback Add comment, and remove dead code. --- src/vm/assemblyname.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/vm/assemblyname.cpp') diff --git a/src/vm/assemblyname.cpp b/src/vm/assemblyname.cpp index f0ed60bb6d..4fd6e20ee8 100644 --- a/src/vm/assemblyname.cpp +++ b/src/vm/assemblyname.cpp @@ -56,15 +56,18 @@ FCIMPL1(Object*, AssemblyNameNative::GetFileInformation, StringObject* filenameU SString sFileName(gc.filename->GetBuffer()); PEImageHolder pImage = PEImage::OpenImage(sFileName, MDInternalImport_NoCache); + // Load the temporary image using a flat layout, instead of + // waiting for it to happen during HasNTHeaders. This allows us to + // get the assembly name for images that contain native code for a + // non-native platform. + PEImageLayoutHolder pLayout(pImage->GetLayout(PEImageLayout::LAYOUT_FLAT, PEImage::LAYOUT_CREATEIFNEEDED)); + // Allow AssemblyLoadContext.GetAssemblyName for native images on CoreCLR if (pImage->HasNTHeaders() && pImage->HasCorHeader() && pImage->HasNativeHeader()) pImage->VerifyIsNIAssembly(); else pImage->VerifyIsAssembly(); - SString sUrl = sFileName; - PEAssembly::PathToUrl(sUrl); - AssemblySpec spec; spec.InitializeSpec(TokenFromRid(mdtAssembly,1),pImage->GetMDImport(),NULL,TRUE); spec.AssemblyNameInit(&gc.result, pImage); -- cgit v1.2.3