zerosharp icon indicating copy to clipboard operation
zerosharp copied to clipboard

no-runtime fails to build/publish

Open stijnherreman opened this issue 1 year ago • 0 comments

I don't know what has changed in the .NET 7 SDK between now and the last commit here, but I had to make some modifications to the no-runtime example.

Now the example builds, publishes and runs, although there is still an error in the output when publishing.

$ dotnet publish -c Release
MSBuild version 17.4.3+7e646be43 for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
  noruntime -> /home/stijn/projects/zerosharp/no-runtime/bin/Release/net7.0/linux-x64/noruntime.dll
  Generating native code
  <unknown>:0: error: Cannot represent a difference across sections
  noruntime -> /home/stijn/projects/zerosharp/no-runtime/bin/Release/net7.0/linux-x64/publish/

$ bin/Release/net7.0/linux-x64/publish/noruntime 
Hello world!

Does the patch below make sense, are they expected changes?

@@ -1,5 +1,6 @@
 using System;
 using System.Runtime;
+using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 
 #region A couple very basic things
@@ -63,6 +64,8 @@ namespace System
 
     namespace Runtime.CompilerServices
     {
+        public class CallConvCdecl { }
+
         public class RuntimeHelpers
         {
             public static unsafe int OffsetToStringData => sizeof(IntPtr) + sizeof(int);
@@ -75,6 +78,13 @@ namespace System.Runtime.InteropServices
     {
         public DllImportAttribute(string dllName) { }
     }
+
+    public sealed class UnmanagedCallersOnlyAttribute : Attribute
+    {
+        public UnmanagedCallersOnlyAttribute() { }
+        public Type[] CallConvs;
+        public string EntryPoint;
+    }
 }
 #endregion
 
@@ -83,6 +93,35 @@ namespace System
 {
     namespace Runtime
     {
+        internal static class __Finalizer
+        {
+            [UnmanagedCallersOnly(EntryPoint = "ProcessFinalizers", CallConvs = new Type[] { typeof(CallConvCdecl) })]
+            public static void ProcessFinalizers() { }
+        }
+
+        internal static unsafe class CachedInterfaceDispatch
+        {
+            [RuntimeExport("RhpCidResolve")]
+            private static unsafe void RhpCidResolve(IntPtr callerTransitionBlockParam, IntPtr pCell) { }
+        }
+
+        internal static unsafe class EH
+        {
+            public ref struct ExInfo { }
+
+            [RuntimeExport("RhThrowHwEx")]
+            public static void RhThrowHwEx(uint exceptionCode, ref ExInfo exInfo) { }
+            [RuntimeExport("RhThrowEx")]
+            public static void RhThrowEx(object exceptionObj, ref ExInfo exInfo) { }
+            [RuntimeExport("RhRethrow")]
+            public static void RhRethrow(ref ExInfo activeExInfo, ref ExInfo exInfo) { }
+
+            [UnmanagedCallersOnly(EntryPoint = "RhpFailFastForPInvokeExceptionPreemp", CallConvs = new Type[] { typeof(CallConvCdecl) })]
+            public static void RhpFailFastForPInvokeExceptionPreemp(IntPtr PInvokeCallsiteReturnAddr, void* pExceptionRecord, void* pContextRecord) { }
+            [RuntimeExport("RhpFailFastForPInvokeExceptionCoop")]
+            public static void RhpFailFastForPInvokeExceptionCoop(IntPtr classlibBreadcrumb, void* pExceptionRecord, void* pContextRecord) { }
+        }
+
         internal sealed class RuntimeExportAttribute : Attribute
         {
             public RuntimeExportAttribute(string entry) { }
@@ -90,6 +129,8 @@ namespace System
     }
 
     class Array<T> : Array { }
+
+    public class Type { }
 }
 
 namespace Internal.Runtime.CompilerHelpers
@@ -102,17 +143,10 @@ namespace Internal.Runtime.CompilerHelpers
         // A couple symbols the generated code will need we park them in this class
         // for no particular reason. These aid in transitioning to/from managed code.
         // Since we don't have a GC, the transition is a no-op.
-        [RuntimeExport("RhpReversePInvoke")]
-        static void RhpReversePInvoke(IntPtr frame) { }
-        [RuntimeExport("RhpReversePInvokeReturn")]
-        static void RhpReversePInvokeReturn(IntPtr frame) { }
         [RuntimeExport("RhpPInvoke")]
         static void RhpPInvoke(IntPtr frame) { }
         [RuntimeExport("RhpPInvokeReturn")]
         static void RhpPInvokeReturn(IntPtr frame) { }
-
-        [RuntimeExport("RhpFallbackFailFast")]
-        static void RhpFallbackFailFast() { while (true) ; }
     }
 }
 #endregion

stijnherreman avatar Jun 18 '23 15:06 stijnherreman