@@ -1060,6 +1060,7 @@ type PEReader =
1060
1060
resourcesAddr: int32
1061
1061
strongnameAddr: int32
1062
1062
vtableFixupsAddr: int32
1063
+ noFileOnDisk: bool
1063
1064
}
1064
1065
1065
1066
[<NoEquality; NoComparison; RequireQualifiedAccess>]
@@ -1537,11 +1538,25 @@ let readBlobHeapAsDouble ctxt vidx = fst (sigptrGetDouble (readBlobHeap ctxt vid
1537
1538
// (e) the start of the native resources attached to the binary if any
1538
1539
// ----------------------------------------------------------------------*)
1539
1540
1540
- let readNativeResources ( pectxt : PEReader ) =
1541
+ // noFileOnDisk indicates that the PE file was read from Memory using OpenILModuleReaderFromBytes
1542
+ // For example the assembly came from a type provider
1543
+ // In this case we eagerly read the native resources into memory
1544
+ let readNativeResources ( pectxt : PEReader ) =
1541
1545
[ if pectxt.nativeResourcesSize <> 0x0 && pectxt.nativeResourcesAddr <> 0x0 then
1542
- let start = pectxt.anyV2P ( pectxt.fileName + " : native resources" , pectxt.nativeResourcesAddr)
1543
- yield ILNativeResource.In ( pectxt.fileName, pectxt.nativeResourcesAddr, start, pectxt.nativeResourcesSize ) ]
1544
-
1546
+ let start = pectxt.anyV2P ( pectxt.fileName + " : native resources" , pectxt.nativeResourcesAddr)
1547
+ if pectxt.noFileOnDisk then
1548
+ #if ! FX_ NO_ LINKEDRESOURCES
1549
+ let unlinkedResource =
1550
+ let linkedResource = seekReadBytes ( pectxt.pefile.GetView()) start pectxt.nativeResourcesSize
1551
+ unlinkResource pectxt.nativeResourcesAddr linkedResource
1552
+ yield ILNativeResource.Out unlinkedResource
1553
+ #else
1554
+ ()
1555
+ #endif
1556
+ else
1557
+ yield ILNativeResource.In ( pectxt.fileName, pectxt.nativeResourcesAddr, start, pectxt.nativeResourcesSize ) ]
1558
+
1559
+
1545
1560
let getDataEndPointsDelayed ( pectxt : PEReader ) ctxtH =
1546
1561
lazy
1547
1562
let ( ctxt : ILMetadataReader ) = getHole ctxtH
@@ -3688,7 +3703,7 @@ let openMetadataReader (fileName, mdfile: BinaryFile, metadataPhysLoc, peinfo, p
3688
3703
// read of the AbsIL module.
3689
3704
// ----------------------------------------------------------------------
3690
3705
3691
- let openPEFileReader ( fileName , pefile : BinaryFile , pdbPath ) =
3706
+ let openPEFileReader ( fileName , pefile : BinaryFile , pdbPath , noFileOnDisk ) =
3692
3707
let pev = pefile.GetView()
3693
3708
(* MSDOS HEADER *)
3694
3709
let peSignaturePhysLoc = seekReadInt32 pev 0x3c
@@ -3881,12 +3896,13 @@ let openPEFileReader (fileName, pefile: BinaryFile, pdbPath) =
3881
3896
pefile= pefile
3882
3897
fileName= fileName
3883
3898
entryPointToken= entryPointToken
3899
+ noFileOnDisk= noFileOnDisk
3884
3900
}
3885
3901
let peinfo = ( subsys, ( subsysMajor, subsysMinor), useHighEnthropyVA, ilOnly, only32, is32bitpreferred, only64, platform, isDll, alignVirt, alignPhys, imageBaseReal)
3886
3902
( metadataPhysLoc, metadataSize, peinfo, pectxt, pev, pdb)
3887
3903
3888
- let openPE ( fileName , pefile , pdbPath , reduceMemoryUsage , ilGlobals ) =
3889
- let ( metadataPhysLoc , _metadataSize , peinfo , pectxt , pev , pdb ) = openPEFileReader ( fileName, pefile, pdbPath)
3904
+ let openPE ( fileName , pefile , pdbPath , reduceMemoryUsage , ilGlobals , noFileOnDisk ) =
3905
+ let ( metadataPhysLoc , _metadataSize , peinfo , pectxt , pev , pdb ) = openPEFileReader ( fileName, pefile, pdbPath, noFileOnDisk )
3890
3906
let ilModule , ilAssemblyRefs = openMetadataReader ( fileName, pefile, metadataPhysLoc, peinfo, pectxt, pev, Some pectxt, reduceMemoryUsage, ilGlobals)
3891
3907
ilModule, ilAssemblyRefs, pdb
3892
3908
@@ -3963,7 +3979,7 @@ let tryMemoryMapWholeFile opts fileName =
3963
3979
3964
3980
let OpenILModuleReaderFromBytes fileName bytes opts =
3965
3981
let pefile = ByteFile( fileName, bytes) :> BinaryFile
3966
- let ilModule , ilAssemblyRefs , pdb = openPE ( fileName, pefile, opts.pdbPath, ( opts.reduceMemoryUsage = ReduceMemoryFlag.Yes), opts.ilGlobals)
3982
+ let ilModule , ilAssemblyRefs , pdb = openPE ( fileName, pefile, opts.pdbPath, ( opts.reduceMemoryUsage = ReduceMemoryFlag.Yes), opts.ilGlobals, true )
3967
3983
new ILModuleReader( ilModule, ilAssemblyRefs, ( fun () -> ClosePdbReader pdb))
3968
3984
3969
3985
let OpenILModuleReader fileName opts =
@@ -4011,7 +4027,7 @@ let OpenILModuleReader fileName opts =
4011
4027
// Then use the metadata blob as the long-lived memory resource.
4012
4028
let disposer , pefileEager = tryMemoryMapWholeFile opts fullPath
4013
4029
use _disposer = disposer
4014
- let ( metadataPhysLoc , metadataSize , peinfo , pectxtEager , pevEager , _pdb ) = openPEFileReader ( fullPath, pefileEager, None)
4030
+ let ( metadataPhysLoc , metadataSize , peinfo , pectxtEager , pevEager , _pdb ) = openPEFileReader ( fullPath, pefileEager, None, false )
4015
4031
let mdfile =
4016
4032
match mdfileOpt with
4017
4033
| Some mdfile -> mdfile
@@ -4025,7 +4041,7 @@ let OpenILModuleReader fileName opts =
4025
4041
// If we are not doing metadata-only, then just go ahead and read all the bytes and hold them either strongly or weakly
4026
4042
// depending on the heuristic
4027
4043
let pefile = createByteFileChunk opts fullPath None
4028
- let ilModule , ilAssemblyRefs , _pdb = openPE ( fullPath, pefile, None, reduceMemoryUsage, opts.ilGlobals)
4044
+ let ilModule , ilAssemblyRefs , _pdb = openPE ( fullPath, pefile, None, reduceMemoryUsage, opts.ilGlobals, false )
4029
4045
new ILModuleReader( ilModule, ilAssemblyRefs, ignore)
4030
4046
4031
4047
if keyOk then
@@ -4043,7 +4059,7 @@ let OpenILModuleReader fileName opts =
4043
4059
//
4044
4060
// We do however care about avoiding locks on files that prevent their deletion during a
4045
4061
// multi-proc build. So use memory mapping, but only for stable files. Other files
4046
- // fill use an in-memory ByteFile
4062
+ // still use an in-memory ByteFile
4047
4063
let _disposer , pefile =
4048
4064
if alwaysMemoryMapFSC || stableFileHeuristicApplies fullPath then
4049
4065
tryMemoryMapWholeFile opts fullPath
@@ -4052,7 +4068,7 @@ let OpenILModuleReader fileName opts =
4052
4068
let disposer = { new IDisposable with member __.Dispose () = () }
4053
4069
disposer, pefile
4054
4070
4055
- let ilModule , ilAssemblyRefs , pdb = openPE ( fullPath, pefile, opts.pdbPath, reduceMemoryUsage, opts.ilGlobals)
4071
+ let ilModule , ilAssemblyRefs , pdb = openPE ( fullPath, pefile, opts.pdbPath, reduceMemoryUsage, opts.ilGlobals, false )
4056
4072
let ilModuleReader = new ILModuleReader( ilModule, ilAssemblyRefs, ( fun () -> ClosePdbReader pdb))
4057
4073
4058
4074
// Readers with PDB reader disposal logic don't go in the cache. Note the PDB reader is only used in static linking.
0 commit comments