[WIP] Enable binding to CoreLib as NI image (#11040)
authorGaurav Khanna <gkhanna@microsoft.com>
Thu, 27 Apr 2017 17:46:47 +0000 (10:46 -0700)
committerGitHub <noreply@github.com>
Thu, 27 Apr 2017 17:46:47 +0000 (10:46 -0700)
Enable binding to CoreLib as NI image

build.cmd
build.sh
src/.nuget/Microsoft.NETCore.Runtime.CoreCLR/runtime.Linux.Microsoft.NETCore.Runtime.CoreCLR.props
src/.nuget/Microsoft.NETCore.Runtime.CoreCLR/runtime.OSX.Microsoft.NETCore.Runtime.CoreCLR.props
src/.nuget/Microsoft.NETCore.Runtime.CoreCLR/runtime.Windows_NT.Microsoft.NETCore.Runtime.CoreCLR.props
src/binder/assemblybinder.cpp
src/build.proj
src/tools/crossgen/crossgen.cpp

index 64945cc..715c6c2 100644 (file)
--- a/build.cmd
+++ b/build.cmd
@@ -454,15 +454,15 @@ if %__BuildNativeCoreLib% EQU 1 (
         set COMPlus_UseWindowsX86CoreLegacyJit=1
     )
 
-    echo "%__CrossgenExe%" %__IbcTuning% /Platform_Assemblies_Paths "%__BinDir%" /out "%__BinDir%\System.Private.CoreLib.ni.dll" "%__BinDir%\System.Private.CoreLib.dll"
-    "%__CrossgenExe%" %__IbcTuning% /Platform_Assemblies_Paths "%__BinDir%" /out "%__BinDir%\System.Private.CoreLib.ni.dll" "%__BinDir%\System.Private.CoreLib.dll" > "%__CrossGenCoreLibLog%" 2>&1
+    echo "%__CrossgenExe%" %__IbcTuning% /Platform_Assemblies_Paths "%__BinDir%"\IL /out "%__BinDir%\System.Private.CoreLib.dll" "%__BinDir%\IL\System.Private.CoreLib.dll"
+    "%__CrossgenExe%" %__IbcTuning% /Platform_Assemblies_Paths "%__BinDir%"\IL /out "%__BinDir%\System.Private.CoreLib.dll" "%__BinDir%\IL\System.Private.CoreLib.dll" > "%__CrossGenCoreLibLog%" 2>&1
     if NOT !errorlevel! == 0 (
         echo %__MsgPrefix%Error: CrossGen System.Private.CoreLib build failed. Refer to %__CrossGenCoreLibLog%
         :: Put it in the same log, helpful for Jenkins
         type %__CrossGenCoreLibLog%
         goto CrossgenFailure
     )
-    "%__CrossgenExe%" /Platform_Assemblies_Paths "%__BinDir%" /CreatePdb "%__BinDir%\PDB" "%__BinDir%\System.Private.CoreLib.ni.dll" >> "%__CrossGenCoreLibLog%" 2>&1
+    "%__CrossgenExe%" /Platform_Assemblies_Paths "%__BinDir%" /CreatePdb "%__BinDir%\PDB" "%__BinDir%\System.Private.CoreLib.dll" >> "%__CrossGenCoreLibLog%" 2>&1
     if NOT !errorlevel! == 0 (
         echo %__MsgPrefix%Error: CrossGen /CreatePdb System.Private.CoreLib build failed. Refer to %__CrossGenCoreLibLog%
         :: Put it in the same log, helpful for Jenkins
index 018cdf0..12b7b72 100755 (executable)
--- a/build.sh
+++ b/build.sh
@@ -379,7 +379,7 @@ build_CoreLib_ni()
 {
     if [ $__SkipCoreCLR == 0 -a -e $__BinDir/crossgen ]; then
         echo "Generating native image for System.Private.CoreLib."
-        $__BinDir/crossgen $__IbcTuning $__BinDir/System.Private.CoreLib.dll
+        $__BinDir/crossgen /Platform_Assemblies_Paths $__BinDir/IL $__IbcTuning /out $__BinDir/System.Private.CoreLib.dll $__BinDir/IL/System.Private.CoreLib.dll
         if [ $? -ne 0 ]; then
             echo "Failed to generate native image for System.Private.CoreLib."
             exit 1
@@ -387,7 +387,7 @@ build_CoreLib_ni()
 
         if [ "$__BuildOS" == "Linux" ]; then
             echo "Generating symbol file for System.Private.CoreLib."
-            $__BinDir/crossgen /CreatePerfMap $__BinDir $__BinDir/System.Private.CoreLib.ni.dll
+            $__BinDir/crossgen /CreatePerfMap $__BinDir $__BinDir/System.Private.CoreLib.dll
             if [ $? -ne 0 ]; then
                 echo "Failed to generate symbol file for System.Private.CoreLib."
                 exit 1
index 4ad2538..5c55497 100644 (file)
@@ -17,7 +17,6 @@
     <NativeBinary Include="$(BinDir)libsosplugin.so" />
     <NativeBinary Include="$(BinDir)System.Globalization.Native.so" />
     <NativeBinary Include="$(BinDir)sosdocsunix.txt" />
-    <NativeBinary Condition="'$(_PlatformDoesNotSupportNiFiles)' != 'true'" Include="$(BinDir)System.Private.CoreLib.ni.dll" />
     <ArchitectureSpecificLibFile Include="$(BinDir)System.Private.CoreLib.dll" />
     <ArchitectureSpecificLibFile Include="$(BinDir)SOS.NETCore.dll" />
     <ArchitectureSpecificToolFile Include="$(BinDir)crossgen" />
index b988a40..1d16788 100644 (file)
@@ -8,7 +8,6 @@
     <NativeBinary Include="$(BinDir)libsos.dylib" />
     <NativeBinary Include="$(BinDir)System.Globalization.Native.dylib" />
     <NativeBinary Include="$(BinDir)sosdocsunix.txt" />
-    <NativeBinary Include="$(BinDir)System.Private.CoreLib.ni.dll" />
     <ArchitectureSpecificLibFile Include="$(BinDir)System.Private.CoreLib.dll" />
     <ArchitectureSpecificLibFile Include="$(BinDir)SOS.NETCore.dll" />
     <ArchitectureSpecificToolFile Include="$(BinDir)crossgen" />
index 436901e..a7d8555 100644 (file)
@@ -19,7 +19,6 @@
     <NativeBinary Include="$(BinDir)mscorrc.debug.dll" />
     <NativeBinary Include="$(BinDir)mscorrc.dll" />
     <NativeBinary Include="$(BinDir)sos.dll" />
-    <NativeBinary Include="$(BinDir)System.Private.CoreLib.ni.dll" />
     <NativeBinary Include="$(UniversalCRTSDKDir)Redist\ucrt\DLLs\$(BuildArch)\*.dll" Condition="'$(BuildType)'=='Release' AND '$(BuildArch)' != 'arm64'" />
     <ArchitectureSpecificLibFile Include="$(BinDir)System.Private.CoreLib.dll" />
     <ArchitectureSpecificLibFile Include="$(BinDir)SOS.NETCore.dll" />
index a73f79f..bd5dd18 100644 (file)
@@ -685,26 +685,21 @@ namespace BINDER_SPACE
 
         StackSString sCoreLib;
 
-        // At run-time, System.Private.CoreLib.ni.dll is typically always available, and
-        // System.Private.CoreLib.dll is typically not.  So check for the NI first.
+        // At run-time, System.Private.CoreLib.dll is expected to be the NI image.
         sCoreLib = sCoreLibDir;
-        sCoreLib.Append(CoreLibName_NI_W);
-        if (!fBindToNativeImage || FAILED(AssemblyBinder::GetAssembly(sCoreLib,
-                                               FALSE /* fInspectionOnly */,
-                                               TRUE /* fIsInGAC */,
-                                               TRUE /* fExplicitBindToNativeImage */,
-                                               &pSystemAssembly)))
-        {
-            // If System.Private.CoreLib.ni.dll is unavailable, look for System.Private.CoreLib.dll instead
-            sCoreLib = sCoreLibDir;
-            sCoreLib.Append(CoreLibName_IL_W);
-            IF_FAIL_GO(AssemblyBinder::GetAssembly(sCoreLib,
+        sCoreLib.Append(CoreLibName_IL_W);
+        BOOL fExplicitBindToNativeImage = (fBindToNativeImage == true)? TRUE:FALSE;
+#if defined(FEATURE_PAL) && !defined(_TARGET_AMD64_)      
+        // Non-Amd64 platforms on non-Windows do not support generating the NI image
+        // as CoreLib.dll. For those, we will bind as IL.
+        fExplicitBindToNativeImage = FALSE;
+#endif // defined(FEATURE_PAL) && !defined(_TARGET_AMD64_)
+        IF_FAIL_GO(AssemblyBinder::GetAssembly(sCoreLib,
                                                    FALSE /* fInspectionOnly */,
                                                    TRUE /* fIsInGAC */,
-                                                   FALSE /* fExplicitBindToNativeImage */,
+                                                   fExplicitBindToNativeImage,
                                                    &pSystemAssembly));
-        }
-
+        
         *ppSystemAssembly = pSystemAssembly.Extract();
 
     Exit:
index 5da94e4..7962d27 100644 (file)
   </Target>
 
   <ItemGroup>
+    <ILToCopy Include="$(BinDir)System.Private.CoreLib.dll"/>
     <PDBSToMove Include="$(BinDir)System.Private.CoreLib.pdb"/>
   </ItemGroup>
 
   <PropertyGroup>
+    <CoreLibPath>$(BinDir)System.Private.CoreLib.dll</CoreLibPath>
     <CoreLibPDBPath>$(BinDir)System.Private.CoreLib.pdb</CoreLibPDBPath>
   </PropertyGroup>
 
+  <Target Name="CopyCoreLib" AfterTargets="Build">
+    <Copy Condition="Exists($(CoreLibPath))"
+        SourceFiles="@(ILToCopy)"
+        DestinationFolder="$(BinDir)IL" />
+  </Target>
+
   <Target Name="MovePDB" AfterTargets="Build">
     <Move Condition="Exists($(CoreLibPDBPath))"
         SourceFiles="@(PDBSToMove)"
index 43e667b..954f4a4 100644 (file)
@@ -311,35 +311,16 @@ void PopulateTPAList(SString path, LPCWSTR pwszMask, SString &refTPAList, bool f
             bool fAddDelimiter = (refTPAList.GetCount() > 0)?true:false;
             bool fAddFileToTPAList = true;
             LPCWSTR pwszFilename = folderEnumerator.GetFileName();
-            if (fCompilingMscorlib)
+            
+            // No NIs are supported when creating NI images (other than NI of System.Private.CoreLib.dll).
+            if (!fCreatePDB)
             {
-                // When compiling CoreLib, no ".ni.dll" should be on the TPAList.
+                // Only CoreLib's ni.dll should be in the TPAList for the compilation of non-mscorlib assemblies.
                 if (StringEndsWith((LPWSTR)pwszFilename, W(".ni.dll")))
                 {
                     fAddFileToTPAList = false;
                 }
             }
-            else
-            {
-                // When creating PDBs, we must ensure that .ni.dlls are in the TPAList
-                if (!fCreatePDB)
-                {
-                    // Only CoreLib's ni.dll should be in the TPAList for the compilation of non-mscorlib assemblies.
-                    if (StringEndsWith((LPWSTR)pwszFilename, W(".ni.dll")))
-                    {
-                        if (!StringEndsWith((LPWSTR)pwszFilename, CoreLibName_NI_W))
-                        {
-                            fAddFileToTPAList = false;
-                        }
-                    }
-                }
-                
-                // Ensure that CoreLib's IL version is also not on the TPAlist for this case.                
-                if (StringEndsWith((LPWSTR)pwszFilename, CoreLibName_IL_W))
-                {
-                    fAddFileToTPAList = false;
-                }
-            }
             
             if (fAddFileToTPAList)
             {