[Mono-bugs] [Bug 81141][Maj] New - Jmp opcode jumping to wrong method with DynamicMethods

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Wed Mar 14 12:05:42 EDT 2007


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 tomba at bat.org.

http://bugzilla.ximian.com/show_bug.cgi?id=81141

--- shadow/81141	2007-03-14 11:05:42.000000000 -0500
+++ shadow/81141.tmp.28331	2007-03-14 11:05:42.000000000 -0500
@@ -0,0 +1,109 @@
+Bug#: 81141
+Product: Mono: Runtime
+Version: 1.2
+OS: GNU/Linux [Other]
+OS Details: Debian Etch x86
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Major
+Component: JIT
+AssignedTo: lupus at ximian.com                            
+ReportedBy: tomba at bat.org               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Jmp opcode jumping to wrong method with DynamicMethods
+
+The program below jumps to a wrong method. In jmpmethod-method it tries to
+jump to main-method, but for some reason the execution continues from
+f1-method.
+
+The output I get from Mono (svn version):
+Entering main
+Entering f1
+Entering jmpmethod
+Jumping to main
+Entering f1              <----
+Entering jmpmethod
+Jumping to f1
+Entering f1
+Entering jmpmethod
+Returning
+
+The output running with CLR:
+Entering main
+Entering f1
+Entering jmpmethod
+Jumping to main
+Entering main
+Entering f1
+Entering jmpmethod
+Jumping to f1
+Entering f1
+Entering jmpmethod
+Returning
+
+---------------------------------
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Reflection.Emit;
+using System.Reflection;
+
+namespace test
+{
+    public class Program
+    {
+        static void Main(string[] args)
+        {
+            DynamicMethod jmpMethod = new DynamicMethod("$jmpmethod",
+typeof(void), new Type[] { typeof(int) }, typeof(Program));
+            DynamicMethod mainMethod = new DynamicMethod("main",
+typeof(void), new Type[] { typeof(int) }, typeof(Program));
+            DynamicMethod f1Method = new DynamicMethod("f1", typeof(void),
+new Type[] { typeof(int) }, typeof(Program));
+
+            ILGenerator ilGen = jmpMethod.GetILGenerator();
+
+            ilGen.EmitWriteLine("Entering jmpmethod");
+
+            List<Label> labelList = new List<Label>();
+            labelList.Add(ilGen.DefineLabel());
+            labelList.Add(ilGen.DefineLabel());
+            ilGen.Emit(OpCodes.Ldarg_0);
+            ilGen.Emit(OpCodes.Switch, labelList.ToArray());
+
+            ilGen.EmitWriteLine("Returning");
+            ilGen.Emit(OpCodes.Ret);
+
+            ilGen.MarkLabel(labelList[0]);
+            ilGen.EmitWriteLine("Jumping to main");
+            ilGen.Emit(OpCodes.Jmp, mainMethod);
+
+            ilGen.MarkLabel(labelList[1]);
+            ilGen.EmitWriteLine("Jumping to f1");
+            ilGen.Emit(OpCodes.Jmp, f1Method);
+
+            // Main
+            ilGen = mainMethod.GetILGenerator();
+            ilGen.EmitWriteLine("Entering main");
+            ilGen.Emit(OpCodes.Jmp, f1Method);
+
+            // f1
+            ilGen = f1Method.GetILGenerator();
+            ilGen.EmitWriteLine("Entering f1");
+            ilGen.Emit(OpCodes.Ldc_I4_1);
+            ilGen.Emit(OpCodes.Ldarg_0);
+            ilGen.Emit(OpCodes.Add);
+            ilGen.Emit(OpCodes.Starg, 0);
+            ilGen.Emit(OpCodes.Jmp, jmpMethod);
+
+
+
+            mainMethod.Invoke(null, new object[] { -1 });
+        }
+    }
+}


More information about the mono-bugs mailing list