[Mono-bugs] [Bug 65352][Maj] New - bogus code generated for DllImport with CallingConvention
bugzilla-daemon@bugzilla.ximian.com
bugzilla-daemon@bugzilla.ximian.com
Sat, 4 Sep 2004 19:55:54 -0400 (EDT)
Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.
Changed by vladimir@pobox.com.
http://bugzilla.ximian.com/show_bug.cgi?id=65352
--- shadow/65352 2004-09-04 19:55:54.000000000 -0400
+++ shadow/65352.tmp.14183 2004-09-04 19:55:54.000000000 -0400
@@ -0,0 +1,115 @@
+Bug#: 65352
+Product: Mono: Runtime
+Version: unspecified
+OS:
+OS Details:
+Status: NEW
+Resolution:
+Severity:
+Priority: Major
+Component: misc
+AssignedTo: mono-bugs@ximian.com
+ReportedBy: vladimir@pobox.com
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Cc: bmaurer@users.sf.net,jackson@ximian.com
+Summary: bogus code generated for DllImport with CallingConvention
+
+[There may be multiple bugs here, one of which seems to be in monodis]
+
+Given this code compiled into a library.dll:
+
+==== library.cs ====
+using System;
+using System.Runtime.InteropServices;
+using System.Security;
+
+namespace Library {
+ public sealed class TestClass {
+ [DllImport("SDL.dll", CallingConvention=CallingConvention.Cdecl,
+ExactSpelling=true), SuppressUnmanagedCodeSecurity]
+ public static extern int SDL_Init (int flags);
+ }
+}
+==== end library.cs ====
+
+and this code, into app.exe with /r:library.dll:
+
+==== app.cs ====
+using System;
+using System.Runtime.InteropServices;
+using System.Security;
+using Library;
+
+public class Driver {
+ [DllImport("SDL.dll", CallingConvention=CallingConvention.Cdecl,
+ExactSpelling=true), SuppressUnmanagedCodeSecurity]
+ public static extern int SDL_Init (int flags);
+
+ public static void Main () {
+ int j = SDL_Init (0);
+ int k = TestClass.SDL_Init (0);
+ }
+}
+==== app.cs ====
+
+If the mono runtime is used to compile app.cs and the resulting .exe is
+used with the .NET runtime, a System.MissingMethodException is generated on
+the first SDL_Init invocation. Here's the relevant IL, and note the
+difference between ildasm and monodis:
+
+==== mcs 1.0.1/mono 1.0.1 compiled, monodis output ====
+ IL_0000: ldc.i4.0
+ IL_0001: call vararg int32 class
+[library]Library.TestClass::SDL_Init(int32)
+ IL_0006: stloc.0
+ IL_0007: ldc.i4.0
+ IL_0008: call int32 class Driver::SDL_Init(int32)
+ IL_000d: stloc.1
+ IL_000e: ret
+==== end ====
+
+==== mcs 1.0.1/mono 1.0.1 compiled, ildasm output ====
+ IL_0000: ldc.i4.0
+ IL_0001: call unmanaged cdecl int32
+[library]Library.TestClass::SDL_Init(int32)
+ IL_0006: stloc.0
+ IL_0007: ldc.i4.0
+ IL_0008: call int32 Driver::SDL_Init(int32)
+ IL_000d: stloc.1
+ IL_000e: ret
+==== end ===
+
+Note that while the second call to the SDL_Init defined within App's class
+looks identical, the first call, which is defined in Library.TestClass, is
+very different -- ildasm interprets it as "unmanaged cdecl", monodis
+interprets it as "vararg".
+
+For comparison, here's the same chunk of code compiled using CSC, and fed
+through both disassemblers again. Note that I'm only recompiling app.exe
+-- I'm using the mono-compiled library.dll.
+
+==== csc/dotnet 1.1 compiled, monodis output ====
+ IL_0000: ldc.i4.0
+ IL_0001: call int32 class [library]Library.TestClass::SDL_Init(int32)
+ IL_0006: stloc.0
+ IL_0007: ldc.i4.0
+ IL_0008: call int32 class Driver::SDL_Init(int32)
+ IL_000d: stloc.1
+ IL_000e: ret
+==== end ====
+
+==== csc/dotnet 1.1 compiled, ildasm output ====
+ IL_0000: ldc.i4.0
+ IL_0001: call int32 [library]Library.TestClass::SDL_Init(int32)
+ IL_0006: stloc.0
+ IL_0007: ldc.i4.0
+ IL_0008: call int32 Driver::SDL_Init(int32)
+ IL_000d: stloc.1
+ IL_000e: ret
+==== end ====
+
+Note that if 'CallingConvention=blah' is removed from library.cs, then the
+code is generated identically to the csc/dotnet compiled code. Also, if
+mcs.exe is used on the dotnet runtime, the correct code is generated.