[Mono-devel-list] patch for bugs in ilasm

Ankit Jain radical at gmail.com
Thu Apr 7 10:49:09 EDT 2005

Attached is a patch for bugs in ilasm.

As almost all the fixes are on the same file (PEAPI.cs), so it wont be
possible to seperate them out.

Also attached are test cases for reproducing the bugs fixed. These were
discovered and fixed while trying to roundtripping on
Microsoft.VisualBasic.dll (monodis ms.vb.dll > vb.il; ilasm /dll vb.il;
PEVerify.exe vb.dll).

After this patch, PEVerify gives zero errors on the final .dll.

The major chunk is for fixing the handling of ValueTypes in ilasm.

case.cs : 
"ref <valuetype>" .. not encoded correctly. Change required in
ClassRefInst.ctor, typeIndex(base) changed to a ValueType. (see patch)

case2.cs : 
 Two problems: 
               1. for array of ValueTypes
               2. ClassRef to ValueType or Enum, gets encoded as a
valuetype. It should be encoded as a ClassRef to System.ValueType or
System.Enum. Only types derived from these are valuetypes.

i1.il : 
 IL allows method params to have same name. ilasm(mono) uses a hashtable to
store named params.. changed that.

i2.il : 
 Type not set for a ByteArrConst (eg. when .param[1] = bytearray (...) )
ByteArray is set to a string by default.

i3.il :
For a float method param
      .param [1] = float64(0x3FB999999999999A)
ILParser converts (0x3f...) to an int64 and then later tries to convert it
into a float, instead of using the in64's exact bit image to build the float.

For Nested classes, the entry in the TypeDef table for the nested class
should have namespace="", as it is built from the NestedClass &
EnclosingClass in the NestedClass table.

t3.il :
An enum declared in IL with no explicit "extends System.Enum" gets
incorrectly encoded as deriving from System.ValueType.
Fixed in the patch.

For testing the .cs testcases, do

mcs case.cs
monodis case.exe > case.il
ilasm case.il

PEVerify.exe case.exe -> This will show the errors.. 

For the .il files just ilasm and peverify them

The files are attached in bugzilla :

Eagerly awaiting feedback.. 

Blog :
Mono hacking : http://mono-nosip.blogspot.com
Personal : http://www.corewars.org/radical
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ilasm.patch
Type: text/x-patch
Size: 17893 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20050407/ffaee44a/attachment.bin 

More information about the Mono-devel-list mailing list