From 5dd4a6304e42d8132e8b33bb4af82f52699ec0e5 Mon Sep 17 00:00:00 2001 From: David Wrighton Date: Mon, 27 Jun 2022 16:36:55 -0700 Subject: [PATCH 1/7] Fix crossgen2 version resilience test - The version resilience test had 2 major bugs in it 1. It was not properly specifying references, so references to other dlls were not being handled 2. It was generating .ni.dll files, which are not actually loaded by the runtime anymore, so even for the code it did generate, the cross module references were not in use. - In addition, fixing the build, caused us to generate an assertion when handling fields of sequential/explicit types from another module, where we did not generate a correct cross module version resilient fixup. (That's what the fix is in CorInfoImpl.ReadyToRun.cs) --- .../JitInterface/CorInfoImpl.ReadyToRun.cs | 22 +++++ src/tests/readytorun/tests/main.cs | 2 +- src/tests/readytorun/tests/mainv1.csproj | 75 ++++++++------ src/tests/readytorun/tests/mainv2.csproj | 98 +++++++++---------- 4 files changed, 114 insertions(+), 83 deletions(-) diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs index 6e62f81bdbf34a..4d0ac0941f82bc 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs @@ -2403,6 +2403,12 @@ private void EncodeFieldBaseOffset(FieldDesc field, CORINFO_FIELD_INFO* pResult, } // ENCODE_NONE } + else if (TypeCannotUseBasePlusOffsetEncoding(pMT.BaseType as MetadataType)) + { + // ENCODE_CHECK_FIELD_OFFSET + AddPrecodeFixup(_compilation.SymbolNodeFactory.CheckFieldOffset(field)); + // No-op other than generating the check field offset fixup + } else { PreventRecursiveFieldInlinesOutsideVersionBubble(field, callerMethod); @@ -2422,6 +2428,22 @@ private void EncodeFieldBaseOffset(FieldDesc field, CORINFO_FIELD_INFO* pResult, } } + private bool TypeCannotUseBasePlusOffsetEncoding(MetadataType type) + { + if (type == null) + return true; + + // Types which are encoded with sequential or explicit layout do not support an aligned base offset, and so we just encode with the exact offset + // of the field, and if that offset is incorrect, the method cannot be used. + if (type.IsSequentialLayout || type.IsExplicitLayout) + return true; + else if (type.BaseType is MetadataType metadataType) + { + return TypeCannotUseBasePlusOffsetEncoding(metadataType); + } + return false; + } + private void getGSCookie(IntPtr* pCookieVal, IntPtr** ppCookieVal) { *pCookieVal = IntPtr.Zero; diff --git a/src/tests/readytorun/tests/main.cs b/src/tests/readytorun/tests/main.cs index 09313a7c3d0dbe..657a15587ff4f8 100644 --- a/src/tests/readytorun/tests/main.cs +++ b/src/tests/readytorun/tests/main.cs @@ -330,7 +330,7 @@ public MyLoadContext() : base(AssemblyLoadContext.GetLoadContext(Assembly.GetExe public void TestMultipleLoads() { - Assembly a = LoadFromAssemblyPath(Path.Combine(Directory.GetCurrentDirectory(), "test.ni.dll")); + Assembly a = LoadFromAssemblyPath(Path.Combine(Directory.GetCurrentDirectory(), "test.dll")); Assert.AreEqual(AssemblyLoadContext.GetLoadContext(a), this); } diff --git a/src/tests/readytorun/tests/mainv1.csproj b/src/tests/readytorun/tests/mainv1.csproj index 9e463a8d8aaa3d..ebff052a7f6711 100644 --- a/src/tests/readytorun/tests/mainv1.csproj +++ b/src/tests/readytorun/tests/mainv1.csproj @@ -24,50 +24,55 @@ set "COMPlus_GCStress=" set "COMPlus_HeapVerify=" set "COMPlus_ReadyToRun=" -DEL test.dll -if exist test.dll ( - echo FAILED to delete test.dll +md IL_DLLS +if not exist IL_DLLS\fieldgetter.dll ( + copy /y fieldgetter.dll IL_DLLS\fieldgetter.dll +) +if not exist IL_DLLS\fieldgetter.dll ( + echo FAILED to copy fieldgetter.dll to IL_DLLS exit /b 1 ) -COPY /Y ..\testv1\test\test.dll test.dll -if not exist test.dll ( - echo FAILED to copy test.dll +if not exist IL_DLLS\mainv1.dll ( + copy /y mainv1.dll IL_DLLS\mainv1.dll +) +if not exist IL_DLLS\mainv1.dll ( + echo FAILED to copy mainv1.dll to IL_DLLS exit /b 1 ) -%Core_Root%\CoreRun.exe %Core_Root%\crossgen2\crossgen2.dll -r:%Core_Root%\*.dll -r:%25CD% -o:test.ni.dll test.dll +%Core_Root%\CoreRun.exe %Core_Root%\crossgen2\crossgen2.dll --map -r:%Core_Root%\*.dll -r:%25CD%\IL_DLLS\fieldgetter.dll -r:%25CD%\IL_DLLS\mainv1.dll -o:test.dll ..\testv1\test\test.dll set CrossGenStatus=!ERRORLEVEL! IF NOT !CrossGenStatus!==0 ( ECHO Crossgen failed with exitcode - !CrossGenStatus! Exit /b 1 ) -if not exist test.ni.dll ( - echo FAILED to build test.ni.dll +if not exist test.map ( + echo FAILED to build test.dll exit /b 1 ) -%Core_Root%\CoreRun.exe %Core_Root%\crossgen2\crossgen2.dll -r:%Core_Root%\*.dll -r:%25CD% -o:fieldgetter.ni.dll fieldgetter.dll +%Core_Root%\CoreRun.exe %Core_Root%\crossgen2\crossgen2.dll --map -r:%Core_Root%\*.dll -r:%25CD%\IL_DLLS\mainv1.dll -r:..\testv1\test\test.dll -o:fieldgetter.dll IL_DLLS\fieldgetter.dll set CrossGenStatus=!ERRORLEVEL! IF NOT !CrossGenStatus!==0 ( ECHO Crossgen failed with exitcode - !CrossGenStatus! Exit /b 1 ) -if not exist fieldgetter.ni.dll ( - echo FAILED to build fieldgetter.ni.dll +if not exist fieldgetter.map ( + echo FAILED to build fieldgetter.dll exit /b 1 ) -%Core_Root%\CoreRun.exe %Core_Root%\crossgen2\crossgen2.dll -r:%Core_Root%\*.dll -r:%25CD% -o:mainv1.ni.dll mainv1.dll +%Core_Root%\CoreRun.exe %Core_Root%\crossgen2\crossgen2.dll --map -r:%Core_Root%\*.dll -r:%25CD%\IL_DLLS\fieldgetter.dll -r:..\testv1\test\test.dll -o:mainv1.dll IL_DLLS\mainv1.dll set CrossGenStatus=!ERRORLEVEL! IF NOT !CrossGenStatus!==0 ( ECHO Crossgen failed with exitcode - !CrossGenStatus! Exit /b 1 ) -if not exist mainv1.ni.dll ( - echo FAILED to build mainv1.ni.dll +if not exist mainv1.map ( + echo FAILED to build mainv1.dll exit /b 1 ) @@ -79,19 +84,29 @@ $(BashCLRTestPreCommands) # Suppress some COMPlus variables for the duration of Crossgen2 execution export -n COMPlus_GCName COMPlus_GCStress COMPlus_HeapVerify COMPlus_ReadyToRun -rm -f test.dll -if [ -f test.dll ] +mkdir IL_DLLS + +if [ ! -f IL_DLLS/fieldgetter.dll ] +then + cp test.dll IL_DLLS/fieldgetter.dll +fi +if [ ! -f IL_DLLS/fieldgetter.dll ] then - echo Failed to delete test.dll + echo Failed to copy fieldgetter.dll to IL_DLLS exit 1 fi -cp ../testv1/test/test.dll test.dll -if [ ! -f test.dll ] + +if [ ! -f IL_DLLS/mainv1.dll ] +then + cp test.dll IL_DLLS/mainv1.dll +fi +if [ ! -f IL_DLLS/mainv1.dll ] then - echo Failed to copy test.dll + echo Failed to copy mainv1.dll to IL_DLLS exit 1 fi -$CORE_ROOT/corerun $CORE_ROOT/crossgen2/crossgen2.dll -r:$CORE_ROOT/*.dll -r:`pwd` -o:test.ni.dll test.dll + +$CORE_ROOT/corerun $CORE_ROOT/crossgen2/crossgen2.dll --map -r:$CORE_ROOT/*.dll -r:`pwd`/IL_DLLS/fieldgetter.dll -r:`pwd`/IL_DLLS/mainv1.dll -o:`pwd`/test.dll `pwd`/../testv1/test/test.dll __cgExitCode=$? if [ $__cgExitCode -ne 0 ] @@ -99,13 +114,13 @@ then echo Crossgen failed with exitcode: $__cgExitCode exit 1 fi -if [ ! -f test.ni.dll ] +if [ ! -f test.map ] then - echo Failed to build test.ni.dll + echo Failed to build test.dll exit 1 fi -$CORE_ROOT/corerun $CORE_ROOT/crossgen2/crossgen2.dll -r:$CORE_ROOT/*.dll -r:`pwd` -o:fieldgetter.ni.dll fieldgetter.dll +$CORE_ROOT/corerun $CORE_ROOT/crossgen2/crossgen2.dll --map -r:$CORE_ROOT/*.dll -r:`pwd`/../testv1/test/test.dll -r:`pwd`/IL_DLLS/mainv1.dll -o:`pwd`/fieldgetter.dll `pwd`/IL_DLLS/fieldgetter.dll __cgExitCode=$? if [ $__cgExitCode -ne 0 ] @@ -113,13 +128,13 @@ then echo Crossgen failed with exitcode: $__cgExitCode exit 1 fi -if [ ! -f fieldgetter.ni.dll ] +if [ ! -f fieldgetter.map ] then - echo Failed to build fieldgetter.ni.dll + echo Failed to build fieldgetter.dll exit 1 fi -$CORE_ROOT/corerun $CORE_ROOT/crossgen2/crossgen2.dll -r:$CORE_ROOT/*.dll -r:`pwd` -o:mainv1.ni.dll mainv1.dll +$CORE_ROOT/corerun $CORE_ROOT/crossgen2/crossgen2.dll --map -r:`pwd`/../testv1/test/test.dll -r:`pwd`/IL_DLLS/fieldgetter.dll -o:`pwd`/mainv1.dll `pwd`/IL_DLLS/mainv1.dll __cgExitCode=$? if [ $__cgExitCode -ne 0 ] @@ -127,9 +142,9 @@ then echo Crossgen failed with exitcode: $__cgExitCode exit 1 fi -if [ ! -f mainv1.ni.dll ] +if [ ! -f mainv1.map ] then - echo Failed to build mainv1.ni.dll + echo Failed to build mainv1.dll exit 1 fi diff --git a/src/tests/readytorun/tests/mainv2.csproj b/src/tests/readytorun/tests/mainv2.csproj index e15b93a3d7fd91..d938e4c05ff73d 100644 --- a/src/tests/readytorun/tests/mainv2.csproj +++ b/src/tests/readytorun/tests/mainv2.csproj @@ -22,60 +22,56 @@ set "COMPlus_GCStress=" set "COMPlus_HeapVerify=" set "COMPlus_ReadyToRun=" -DEL test.dll -if exist test.dll ( - echo FAILED to delete test.dll +md IL_DLLS +if not exist IL_DLLS\fieldgetter.dll ( + copy /y fieldgetter.dll IL_DLLS\fieldgetter.dll +) +if not exist IL_DLLS\fieldgetter.dll ( + echo FAILED to copy fieldgetter.dll to IL_DLLS exit /b 1 ) -COPY /Y ..\testv1\test\test.dll test.dll -if not exist test.dll ( - echo FAILED to copy test.dll +if not exist IL_DLLS\mainv2.dll ( + copy /y mainv2.dll IL_DLLS\mainv2.dll +) +if not exist IL_DLLS\mainv2.dll ( + echo FAILED to copy mainv2.dll to IL_DLLS exit /b 1 ) -%Core_Root%\CoreRun.exe %Core_Root%\crossgen2\crossgen2.dll -r:%Core_Root%\*.dll -r:%25CD% -o:mainv2.ni.dll mainv2.dll +REM NOTE THAT THIS IS WHERE WE BUILD THE R2R IMAGE using V2 of test not V1 +%Core_Root%\CoreRun.exe %Core_Root%\crossgen2\crossgen2.dll --map -r:%Core_Root%\*.dll -r:%25CD%\IL_DLLS\fieldgetter.dll -r:%25CD%\IL_DLLS\mainv2.dll -o:test.dll ..\testv2\test\test.dll set CrossGenStatus=!ERRORLEVEL! IF NOT !CrossGenStatus!==0 ( ECHO Crossgen failed with exitcode - !CrossGenStatus! Exit /b 1 ) -if not exist mainv2.ni.dll ( - echo FAILED to build mainv2.ni.dll +if not exist test.map ( + echo FAILED to build test.dll exit /b 1 ) -%Core_Root%\CoreRun.exe %Core_Root%\crossgen2\crossgen2.dll -r:%Core_Root%\*.dll -r:%25CD% -o:fieldgetter.ni.dll fieldgetter.dll +%Core_Root%\CoreRun.exe %Core_Root%\crossgen2\crossgen2.dll --map -r:%Core_Root%\*.dll -r:%25CD%\IL_DLLS\mainv2.dll -r:..\testv1\test\test.dll -o:fieldgetter.dll IL_DLLS\fieldgetter.dll set CrossGenStatus=!ERRORLEVEL! IF NOT !CrossGenStatus!==0 ( ECHO Crossgen failed with exitcode - !CrossGenStatus! Exit /b 1 ) -if not exist fieldgetter.ni.dll ( - echo FAILED to build fieldgetter.ni.dll - exit /b 1 -) -DEL test.dll -if exist test.dll ( - echo FAILED to delete test.dll - exit /b 1 -) -COPY /Y ..\testv2\test\test.dll test.dll -if not exist test.dll ( - echo FAILED to copy test.dll +if not exist fieldgetter.map ( + echo FAILED to build fieldgetter.dll exit /b 1 ) -%Core_Root%\CoreRun.exe %Core_Root%\crossgen2\crossgen2.dll -r:%Core_Root%\*.dll -r:%25CD% -o:test.ni.dll test.dll +%Core_Root%\CoreRun.exe %Core_Root%\crossgen2\crossgen2.dll --map -r:%Core_Root%\*.dll -r:%25CD%\IL_DLLS\fieldgetter.dll -r:..\testv1\test\test.dll -o:mainv2.dll IL_DLLS\mainv2.dll set CrossGenStatus=!ERRORLEVEL! IF NOT !CrossGenStatus!==0 ( ECHO Crossgen failed with exitcode - !CrossGenStatus! Exit /b 1 ) -if not exist test.ni.dll ( - echo FAILED to build test.ni.dll +if not exist mainv2.map ( + echo FAILED to build mainv2.dll exit /b 1 ) @@ -87,34 +83,30 @@ $(BashCLRTestPreCommands) # Suppress some COMPlus variables for the duration of Crossgen2 execution export -n COMPlus_GCName COMPlus_GCStress COMPlus_HeapVerify COMPlus_ReadyToRun -rm -f test.dll -if [ -f test.dll ] +mkdir IL_DLLS + +if [ ! -f IL_DLLS/fieldgetter.dll ] then - echo Failed to delete test.dll - exit 1 + cp test.dll IL_DLLS/fieldgetter.dll fi -cp ../testv1/test/test.dll test.dll -if [ ! -f test.dll ] +if [ ! -f IL_DLLS/fieldgetter.dll ] then - echo Failed to copy test.dll + echo Failed to copy fieldgetter.dll to IL_DLLS exit 1 fi -$CORE_ROOT/corerun $CORE_ROOT/crossgen2/crossgen2.dll -r:$CORE_ROOT/*.dll -r:`pwd` -o:mainv2.ni.dll mainv2.dll - -__cgExitCode=$? -if [ $__cgExitCode -ne 0 ] +if [ ! -f IL_DLLS/mainv2.dll ] then - echo Crossgen failed with exitcode: $__cgExitCode - exit 1 + cp test.dll IL_DLLS/mainv2.dll fi -if [ ! -f mainv2.ni.dll ] +if [ ! -f IL_DLLS/mainv2.dll ] then - echo Failed to build mainv2.ni.dll + echo Failed to copy mainv2.dll to IL_DLLS exit 1 fi -$CORE_ROOT/corerun $CORE_ROOT/crossgen2/crossgen2.dll -r:$CORE_ROOT/*.dll -r:`pwd` -o:fieldgetter.ni.dll fieldgetter.dll +# NOTE THAT THIS IS WHERE WE BUILD THE R2R IMAGE using V2 of test not V1 +$CORE_ROOT/corerun $CORE_ROOT/crossgen2/crossgen2.dll --map -r:$CORE_ROOT/*.dll -r:`pwd`/IL_DLLS/fieldgetter.dll -r:`pwd`/IL_DLLS/mainv2.dll -o:`pwd`/test.dll `pwd`/../testv2/test/test.dll __cgExitCode=$? if [ $__cgExitCode -ne 0 ] @@ -122,25 +114,27 @@ then echo Crossgen failed with exitcode: $__cgExitCode exit 1 fi -if [ ! -f fieldgetter.ni.dll ] +if [ ! -f test.map ] then - echo Failed to build fieldgetter.ni.dll + echo Failed to build test.dll exit 1 fi -rm -f test.dll -if [ -f test.dll ] + +$CORE_ROOT/corerun $CORE_ROOT/crossgen2/crossgen2.dll --map -r:$CORE_ROOT/*.dll -r:`pwd`/../testv1/test/test.dll -r:`pwd`/IL_DLLS/mainv2.dll -o:`pwd`/fieldgetter.dll `pwd`/IL_DLLS/fieldgetter.dll + +__cgExitCode=$? +if [ $__cgExitCode -ne 0 ] then - echo Failed to delete test.dll + echo Crossgen failed with exitcode: $__cgExitCode exit 1 fi -cp ../testv2/test/test.dll test.dll -if [ ! -f test.dll ] +if [ ! -f fieldgetter.map ] then - echo Failed to copy test.dll + echo Failed to build fieldgetter.dll exit 1 fi -$CORE_ROOT/corerun $CORE_ROOT/crossgen2/crossgen2.dll -r:$CORE_ROOT/*.dll -r:`pwd` -o:test.ni.dll test.dll +$CORE_ROOT/corerun $CORE_ROOT/crossgen2/crossgen2.dll --map -r:`pwd`/../testv1/test/test.dll -r:`pwd`/IL_DLLS/fieldgetter.dll -o:`pwd`/mainv2.dll `pwd`/IL_DLLS/mainv2.dll __cgExitCode=$? if [ $__cgExitCode -ne 0 ] @@ -148,9 +142,9 @@ then echo Crossgen failed with exitcode: $__cgExitCode exit 1 fi -if [ ! -f test.ni.dll ] +if [ ! -f mainv2.map ] then - echo Failed to build test.ni.dll + echo Failed to build mainv2.dll exit 1 fi From 7ab85182451ab49def9c2ad7586865d29e0685e8 Mon Sep 17 00:00:00 2001 From: David Wrighton Date: Mon, 27 Jun 2022 18:43:37 -0700 Subject: [PATCH 2/7] Try to fix bash issue --- src/tests/readytorun/tests/mainv1.csproj | 6 +++--- src/tests/readytorun/tests/mainv2.csproj | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/tests/readytorun/tests/mainv1.csproj b/src/tests/readytorun/tests/mainv1.csproj index ebff052a7f6711..6547f8ddccbebd 100644 --- a/src/tests/readytorun/tests/mainv1.csproj +++ b/src/tests/readytorun/tests/mainv1.csproj @@ -106,7 +106,7 @@ then exit 1 fi -$CORE_ROOT/corerun $CORE_ROOT/crossgen2/crossgen2.dll --map -r:$CORE_ROOT/*.dll -r:`pwd`/IL_DLLS/fieldgetter.dll -r:`pwd`/IL_DLLS/mainv1.dll -o:`pwd`/test.dll `pwd`/../testv1/test/test.dll +$CORE_ROOT/corerun $CORE_ROOT/crossgen2/crossgen2.dll --map -r:$CORE_ROOT/*.dll -r:IL_DLLS/fieldgetter.dll -r:IL_DLLS/mainv1.dll -o:test.dll ../testv1/test/test.dll __cgExitCode=$? if [ $__cgExitCode -ne 0 ] @@ -120,7 +120,7 @@ then exit 1 fi -$CORE_ROOT/corerun $CORE_ROOT/crossgen2/crossgen2.dll --map -r:$CORE_ROOT/*.dll -r:`pwd`/../testv1/test/test.dll -r:`pwd`/IL_DLLS/mainv1.dll -o:`pwd`/fieldgetter.dll `pwd`/IL_DLLS/fieldgetter.dll +$CORE_ROOT/corerun $CORE_ROOT/crossgen2/crossgen2.dll --map -r:$CORE_ROOT/*.dll -r:../testv1/test/test.dll -r:IL_DLLS/mainv1.dll -o:fieldgetter.dll IL_DLLS/fieldgetter.dll __cgExitCode=$? if [ $__cgExitCode -ne 0 ] @@ -134,7 +134,7 @@ then exit 1 fi -$CORE_ROOT/corerun $CORE_ROOT/crossgen2/crossgen2.dll --map -r:`pwd`/../testv1/test/test.dll -r:`pwd`/IL_DLLS/fieldgetter.dll -o:`pwd`/mainv1.dll `pwd`/IL_DLLS/mainv1.dll +$CORE_ROOT/corerun $CORE_ROOT/crossgen2/crossgen2.dll --map -r:$CORE_ROOT/*.dll -r:../testv1/test/test.dll -r:/IL_DLLS/fieldgetter.dll -o:mainv1.dll IL_DLLS/mainv1.dll __cgExitCode=$? if [ $__cgExitCode -ne 0 ] diff --git a/src/tests/readytorun/tests/mainv2.csproj b/src/tests/readytorun/tests/mainv2.csproj index d938e4c05ff73d..95086af6ac5a00 100644 --- a/src/tests/readytorun/tests/mainv2.csproj +++ b/src/tests/readytorun/tests/mainv2.csproj @@ -106,7 +106,7 @@ then fi # NOTE THAT THIS IS WHERE WE BUILD THE R2R IMAGE using V2 of test not V1 -$CORE_ROOT/corerun $CORE_ROOT/crossgen2/crossgen2.dll --map -r:$CORE_ROOT/*.dll -r:`pwd`/IL_DLLS/fieldgetter.dll -r:`pwd`/IL_DLLS/mainv2.dll -o:`pwd`/test.dll `pwd`/../testv2/test/test.dll +$CORE_ROOT/corerun $CORE_ROOT/crossgen2/crossgen2.dll --map -r:$CORE_ROOT/*.dll -r:IL_DLLS/fieldgetter.dll -r:IL_DLLS/mainv2.dll -o:test.dll ../testv2/test/test.dll __cgExitCode=$? if [ $__cgExitCode -ne 0 ] @@ -120,7 +120,7 @@ then exit 1 fi -$CORE_ROOT/corerun $CORE_ROOT/crossgen2/crossgen2.dll --map -r:$CORE_ROOT/*.dll -r:`pwd`/../testv1/test/test.dll -r:`pwd`/IL_DLLS/mainv2.dll -o:`pwd`/fieldgetter.dll `pwd`/IL_DLLS/fieldgetter.dll +$CORE_ROOT/corerun $CORE_ROOT/crossgen2/crossgen2.dll --map -r:$CORE_ROOT/*.dll -r:../testv1/test/test.dll -r:IL_DLLS/mainv2.dll -o:fieldgetter.dll IL_DLLS/fieldgetter.dll __cgExitCode=$? if [ $__cgExitCode -ne 0 ] @@ -134,7 +134,7 @@ then exit 1 fi -$CORE_ROOT/corerun $CORE_ROOT/crossgen2/crossgen2.dll --map -r:`pwd`/../testv1/test/test.dll -r:`pwd`/IL_DLLS/fieldgetter.dll -o:`pwd`/mainv2.dll `pwd`/IL_DLLS/mainv2.dll +$CORE_ROOT/corerun $CORE_ROOT/crossgen2/crossgen2.dll --map -r:$CORE_ROOT/*.dll -r:../testv1/test/test.dll -r:IL_DLLS/fieldgetter.dll -o:mainv2.dll IL_DLLS/mainv2.dll __cgExitCode=$? if [ $__cgExitCode -ne 0 ] From 6aa5ad80bc4dcadc0dd4abc9ba463339a661e5d7 Mon Sep 17 00:00:00 2001 From: David Wrighton Date: Tue, 28 Jun 2022 11:34:42 -0700 Subject: [PATCH 3/7] Try to fix Linux again, and disable p/invoke inlining across version boundaries --- .../JitInterface/CorInfoImpl.ReadyToRun.cs | 7 +++++++ src/tests/readytorun/tests/mainv1.csproj | 4 ++-- src/tests/readytorun/tests/mainv2.csproj | 4 ++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs index 4d0ac0941f82bc..f51650f0b07195 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs @@ -2569,6 +2569,13 @@ private bool pInvokeMarshalingRequired(CORINFO_METHOD_STRUCT_* handle, CORINFO_S return false; } + // If this method is in another versioning unit, then the compilation cannot inline the pinvoke (as we aren't currently + // able to construct a token correctly to refer to the pinvoke method. + if (!_compilation.CompilationModuleGroup.VersionsWithMethodBody(method)) + { + return true; + } + MethodIL stubIL = null; try { diff --git a/src/tests/readytorun/tests/mainv1.csproj b/src/tests/readytorun/tests/mainv1.csproj index 6547f8ddccbebd..91c5983c739516 100644 --- a/src/tests/readytorun/tests/mainv1.csproj +++ b/src/tests/readytorun/tests/mainv1.csproj @@ -88,7 +88,7 @@ mkdir IL_DLLS if [ ! -f IL_DLLS/fieldgetter.dll ] then - cp test.dll IL_DLLS/fieldgetter.dll + cp fieldgetter.dll IL_DLLS/fieldgetter.dll fi if [ ! -f IL_DLLS/fieldgetter.dll ] then @@ -98,7 +98,7 @@ fi if [ ! -f IL_DLLS/mainv1.dll ] then - cp test.dll IL_DLLS/mainv1.dll + cp mainv1.dll IL_DLLS/mainv1.dll fi if [ ! -f IL_DLLS/mainv1.dll ] then diff --git a/src/tests/readytorun/tests/mainv2.csproj b/src/tests/readytorun/tests/mainv2.csproj index 95086af6ac5a00..d37f8aa6cba5d7 100644 --- a/src/tests/readytorun/tests/mainv2.csproj +++ b/src/tests/readytorun/tests/mainv2.csproj @@ -87,7 +87,7 @@ mkdir IL_DLLS if [ ! -f IL_DLLS/fieldgetter.dll ] then - cp test.dll IL_DLLS/fieldgetter.dll + cp fieldgetter.dll IL_DLLS/fieldgetter.dll fi if [ ! -f IL_DLLS/fieldgetter.dll ] then @@ -97,7 +97,7 @@ fi if [ ! -f IL_DLLS/mainv2.dll ] then - cp test.dll IL_DLLS/mainv2.dll + cp mainv2.dll IL_DLLS/mainv2.dll fi if [ ! -f IL_DLLS/mainv2.dll ] then From 1b246a5b60d50253c577e5e860e83b4e71bef507 Mon Sep 17 00:00:00 2001 From: David Wrighton Date: Tue, 28 Jun 2022 14:31:07 -0700 Subject: [PATCH 4/7] Address assertion around byte array load of R2R file on unix Tweak bash script again --- src/coreclr/vm/peimagelayout.cpp | 8 +++++--- src/tests/readytorun/tests/mainv1.csproj | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/coreclr/vm/peimagelayout.cpp b/src/coreclr/vm/peimagelayout.cpp index 2cf519425da2a9..16b9f6b4a61ea7 100644 --- a/src/coreclr/vm/peimagelayout.cpp +++ b/src/coreclr/vm/peimagelayout.cpp @@ -65,6 +65,7 @@ PEImageLayout* PEImageLayout::LoadConverted(PEImage* pOwner) _ASSERTE(!pOwner->HasLoadedLayout()); ReleaseHolder pFlat; + bool createdFromFile = false; if (pOwner->IsOpened()) { pFlat = (FlatImageLayout*)pOwner->GetFlatLayout(); @@ -73,6 +74,7 @@ PEImageLayout* PEImageLayout::LoadConverted(PEImage* pOwner) else if (pOwner->IsFile()) { pFlat = new FlatImageLayout(pOwner); + createdFromFile = true; } if (pFlat == NULL || !pFlat->CheckILOnlyFormat()) @@ -81,11 +83,11 @@ PEImageLayout* PEImageLayout::LoadConverted(PEImage* pOwner) // TODO: enable on OSX eventually // right now we have binaries that will trigger this in a singlefile bundle. #ifdef TARGET_LINUX - // we should not see R2R files here on Unix. - // ConvertedImageLayout may be able to handle them, but the fact that we were unable to + // we should not see R2R files here on Unix unless the image is loaded from a byte array. + // ConvertedImageLayout is 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(!pFlat->HasReadyToRunHeader() || !createdFromFile); #endif if (!pFlat->HasReadyToRunHeader() && !pFlat->HasWriteableSections()) diff --git a/src/tests/readytorun/tests/mainv1.csproj b/src/tests/readytorun/tests/mainv1.csproj index 91c5983c739516..ee71d03f3c1feb 100644 --- a/src/tests/readytorun/tests/mainv1.csproj +++ b/src/tests/readytorun/tests/mainv1.csproj @@ -134,7 +134,7 @@ then exit 1 fi -$CORE_ROOT/corerun $CORE_ROOT/crossgen2/crossgen2.dll --map -r:$CORE_ROOT/*.dll -r:../testv1/test/test.dll -r:/IL_DLLS/fieldgetter.dll -o:mainv1.dll IL_DLLS/mainv1.dll +$CORE_ROOT/corerun $CORE_ROOT/crossgen2/crossgen2.dll --map -r:$CORE_ROOT/*.dll -r:../testv1/test/test.dll -r:IL_DLLS/fieldgetter.dll -o:mainv1.dll IL_DLLS/mainv1.dll __cgExitCode=$? if [ $__cgExitCode -ne 0 ] From 28adc1b445c7f158b88b2d483a95cc6a913473d1 Mon Sep 17 00:00:00 2001 From: David Wrighton Date: Wed, 29 Jun 2022 11:19:08 -0700 Subject: [PATCH 5/7] Add progress messages to test to diagnose failure on MacOS --- src/tests/readytorun/tests/main.cs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/tests/readytorun/tests/main.cs b/src/tests/readytorun/tests/main.cs index 657a15587ff4f8..92a0cce84c0dbb 100644 --- a/src/tests/readytorun/tests/main.cs +++ b/src/tests/readytorun/tests/main.cs @@ -424,57 +424,86 @@ static void TestLoadR2RImageFromByteArray() static void RunAllTests() { + Console.WriteLine("TestVirtualMethodCalls"); TestVirtualMethodCalls(); + Console.WriteLine("TestMovedVirtualMethod"); TestMovedVirtualMethods(); + Console.WriteLine("TestConstrainedMethodCalls"); TestConstrainedMethodCalls(); + Console.WriteLine("TestConstrainedMethodCalls_Unsupported"); TestConstrainedMethodCalls_Unsupported(); + Console.WriteLine("TestInterop"); TestInterop(); + Console.WriteLine("TestStaticFields"); TestStaticFields(); + Console.WriteLine("TestPreInitializedArray"); TestPreInitializedArray(); + Console.WriteLine("TestMultiDimmArray"); TestMultiDimmArray(); + Console.WriteLine("TestGenericVirtualMethod"); TestGenericVirtualMethod(); + Console.WriteLine("TestMovedGenericVirtualMethod"); TestMovedGenericVirtualMethod(); + Console.WriteLine("TestGenericNonVirtualMethod"); TestGenericNonVirtualMethod(); + Console.WriteLine("TestGenericOverStruct"); TestGenericOverStruct(); + Console.WriteLine("TestInstanceFields"); TestInstanceFields(); + Console.WriteLine("TestInstanceFieldsWithLayout"); TestInstanceFieldsWithLayout(); + Console.WriteLine("TestInheritingFromGrowingBase"); TestInheritingFromGrowingBase(); + Console.WriteLine("TestGrowingStruct"); TestGrowingStruct(); + Console.WriteLine("TestChangingStruct"); TestChangingStruct(); + Console.WriteLine("TestChangingHFAStruct"); TestChangingHFAStruct(); + Console.WriteLine("TestGetType"); TestGetType(); + Console.WriteLine("TestMultipleLoads"); TestMultipleLoads(); + Console.WriteLine("TestFieldLayoutNGenMixAndMatch"); TestFieldLayoutNGenMixAndMatch(); + Console.WriteLine("TestStaticBaseCSE"); TestStaticBaseCSE(); + Console.WriteLine("TestIsInstCSE"); TestIsInstCSE(); + Console.WriteLine("TestCastClassCSE"); TestCastClassCSE(); + Console.WriteLine("TestRangeCheckElimination"); TestRangeCheckElimination(); + Console.WriteLine("TestOpenClosedDelegate"); TestOpenClosedDelegate(); + Console.WriteLine("GenericLdtokenFieldsTest"); GenericLdtokenFieldsTest(); + Console.WriteLine("RVAFieldTest"); RVAFieldTest(); + Console.WriteLine("TestLoadR2RImageFromByteArray"); TestLoadR2RImageFromByteArray(); } From 349d3333856340db34fc87186e914b72c3c81db4 Mon Sep 17 00:00:00 2001 From: David Wrighton Date: Wed, 29 Jun 2022 14:16:11 -0700 Subject: [PATCH 6/7] Break out R2R assembly load test into separate test so that the main thrust of the test can be kept active --- src/coreclr/vm/peimagelayout.cpp | 8 +- .../tests/loadr2rdll_as_bytearray.cs | 31 ++++++++ .../tests/loadr2rdll_as_bytearray.csproj | 78 +++++++++++++++++++ src/tests/readytorun/tests/main.cs | 13 ---- 4 files changed, 112 insertions(+), 18 deletions(-) create mode 100644 src/tests/readytorun/tests/loadr2rdll_as_bytearray.cs create mode 100644 src/tests/readytorun/tests/loadr2rdll_as_bytearray.csproj diff --git a/src/coreclr/vm/peimagelayout.cpp b/src/coreclr/vm/peimagelayout.cpp index 16b9f6b4a61ea7..2cf519425da2a9 100644 --- a/src/coreclr/vm/peimagelayout.cpp +++ b/src/coreclr/vm/peimagelayout.cpp @@ -65,7 +65,6 @@ PEImageLayout* PEImageLayout::LoadConverted(PEImage* pOwner) _ASSERTE(!pOwner->HasLoadedLayout()); ReleaseHolder pFlat; - bool createdFromFile = false; if (pOwner->IsOpened()) { pFlat = (FlatImageLayout*)pOwner->GetFlatLayout(); @@ -74,7 +73,6 @@ PEImageLayout* PEImageLayout::LoadConverted(PEImage* pOwner) else if (pOwner->IsFile()) { pFlat = new FlatImageLayout(pOwner); - createdFromFile = true; } if (pFlat == NULL || !pFlat->CheckILOnlyFormat()) @@ -83,11 +81,11 @@ PEImageLayout* PEImageLayout::LoadConverted(PEImage* pOwner) // TODO: enable on OSX eventually // right now we have binaries that will trigger this in a singlefile bundle. #ifdef TARGET_LINUX - // we should not see R2R files here on Unix unless the image is loaded from a byte array. - // ConvertedImageLayout is able to handle them, but the fact that we were unable to + // we should not see R2R files here on Unix. + // 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() || !createdFromFile); + _ASSERTE(!pFlat->HasReadyToRunHeader()); #endif if (!pFlat->HasReadyToRunHeader() && !pFlat->HasWriteableSections()) diff --git a/src/tests/readytorun/tests/loadr2rdll_as_bytearray.cs b/src/tests/readytorun/tests/loadr2rdll_as_bytearray.cs new file mode 100644 index 00000000000000..f24606f2b68657 --- /dev/null +++ b/src/tests/readytorun/tests/loadr2rdll_as_bytearray.cs @@ -0,0 +1,31 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// + +using System; +using System.Reflection; +using System.IO; + +class Program +{ + static int Main() + { + Assembly assembly1 = typeof(Program).Assembly; + + byte[] array = File.ReadAllBytes(assembly1.Location); + Assembly assembly2 = Assembly.Load(array); + + if (assembly2.FullName != assembly1.FullName) + { + Console.WriteLine("names do not match"); + return 1; + } + + if (Object.ReferenceEquals(assembly1, assembly2)) + { + Console.WriteLine("did not load as a separate assembly"); + return 2; + } + return 100; + } +} \ No newline at end of file diff --git a/src/tests/readytorun/tests/loadr2rdll_as_bytearray.csproj b/src/tests/readytorun/tests/loadr2rdll_as_bytearray.csproj new file mode 100644 index 00000000000000..5c5678ef031f27 --- /dev/null +++ b/src/tests/readytorun/tests/loadr2rdll_as_bytearray.csproj @@ -0,0 +1,78 @@ + + + exe + false + + + + + + + + + diff --git a/src/tests/readytorun/tests/main.cs b/src/tests/readytorun/tests/main.cs index 92a0cce84c0dbb..dac4510948451d 100644 --- a/src/tests/readytorun/tests/main.cs +++ b/src/tests/readytorun/tests/main.cs @@ -412,16 +412,6 @@ static void RVAFieldTest() Assert.AreEqual(value[i], (byte)(9 - i)); } - static void TestLoadR2RImageFromByteArray() - { - Assembly assembly1 = typeof(Program).Assembly; - - byte[] array = File.ReadAllBytes(assembly1.Location); - Assembly assembly2 = Assembly.Load(array); - - Assert.AreEqual(assembly2.FullName, assembly1.FullName); - } - static void RunAllTests() { Console.WriteLine("TestVirtualMethodCalls"); @@ -502,9 +492,6 @@ static void RunAllTests() Console.WriteLine("RVAFieldTest"); RVAFieldTest(); - - Console.WriteLine("TestLoadR2RImageFromByteArray"); - TestLoadR2RImageFromByteArray(); } static int Main() From fb2744b76102c7c4771b015eac47a1f812d81e54 Mon Sep 17 00:00:00 2001 From: David Wrighton Date: Thu, 30 Jun 2022 14:16:16 -0700 Subject: [PATCH 7/7] Finish up, and make test --- .../tests/loadr2rdll_as_bytearray.cs | 31 -------- .../tests/loadr2rdll_as_bytearray.csproj | 78 ------------------- src/tests/readytorun/tests/main.cs | 14 ++++ 3 files changed, 14 insertions(+), 109 deletions(-) delete mode 100644 src/tests/readytorun/tests/loadr2rdll_as_bytearray.cs delete mode 100644 src/tests/readytorun/tests/loadr2rdll_as_bytearray.csproj diff --git a/src/tests/readytorun/tests/loadr2rdll_as_bytearray.cs b/src/tests/readytorun/tests/loadr2rdll_as_bytearray.cs deleted file mode 100644 index f24606f2b68657..00000000000000 --- a/src/tests/readytorun/tests/loadr2rdll_as_bytearray.cs +++ /dev/null @@ -1,31 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// - -using System; -using System.Reflection; -using System.IO; - -class Program -{ - static int Main() - { - Assembly assembly1 = typeof(Program).Assembly; - - byte[] array = File.ReadAllBytes(assembly1.Location); - Assembly assembly2 = Assembly.Load(array); - - if (assembly2.FullName != assembly1.FullName) - { - Console.WriteLine("names do not match"); - return 1; - } - - if (Object.ReferenceEquals(assembly1, assembly2)) - { - Console.WriteLine("did not load as a separate assembly"); - return 2; - } - return 100; - } -} \ No newline at end of file diff --git a/src/tests/readytorun/tests/loadr2rdll_as_bytearray.csproj b/src/tests/readytorun/tests/loadr2rdll_as_bytearray.csproj deleted file mode 100644 index 5c5678ef031f27..00000000000000 --- a/src/tests/readytorun/tests/loadr2rdll_as_bytearray.csproj +++ /dev/null @@ -1,78 +0,0 @@ - - - exe - false - - - - - - - - - diff --git a/src/tests/readytorun/tests/main.cs b/src/tests/readytorun/tests/main.cs index dac4510948451d..5a13733db28bdf 100644 --- a/src/tests/readytorun/tests/main.cs +++ b/src/tests/readytorun/tests/main.cs @@ -412,6 +412,16 @@ static void RVAFieldTest() Assert.AreEqual(value[i], (byte)(9 - i)); } + static void TestLoadR2RImageFromByteArray() + { + Assembly assembly1 = typeof(Program).Assembly; + + byte[] array = File.ReadAllBytes(assembly1.Location); + Assembly assembly2 = Assembly.Load(array); + + Assert.AreEqual(assembly2.FullName, assembly1.FullName); + } + static void RunAllTests() { Console.WriteLine("TestVirtualMethodCalls"); @@ -492,6 +502,10 @@ static void RunAllTests() Console.WriteLine("RVAFieldTest"); RVAFieldTest(); + +// Disable for https://github.com/dotnet/runtime/issues/71507 +// Console.WriteLine("TestLoadR2RImageFromByteArray"); +// TestLoadR2RImageFromByteArray(); } static int Main()