runtime: ilasm throws an error when partly-defined .line directives are used

Description

ILAsm throws the following error:

"Could not create output file, error code=0x80004005"

when the input source file includes a partly-defined .line directive, for example:

.method public hidebysig static int32 Foo(int32 a) cil managed { .line 15:3 ‘some_external_file.ext’ IL_0000: nop IL_0001: ret }

Partly-defined .line directives are those which do not specify all of the optional start/end line/column parameters.

Configuration

.NET 5.0 ilasm

Other information

There are two problems related to this issue in the ilasm implementation:

1. .line directive rules

For .NET Core there is a discrepancy between ILAsm and Portable PDB specification and requirements for .line directive.

  • ILASM specification [Expert .NET 2.0 IL Assembler - CHAPTER 19 MULTILANGUAGE PROJECTS page: 407] .line <start_line>, <end_line> : <start_col>, <end_col> ‘<file_name>’ All parameters except the <start_line> may be omitted; in this case they are replaced with the following default values:

<end_line> = <start_line> <end_col> = <start_col> <start_col> = 1 <file_name> = taken from the previous .line directive

… End Line is greater or equal to Start Line. If Start Line is equal to End Line then End Column is greater than Start Column.

As it can be seen Portable PDB requires EndColumn to be greater than StartColumn in cases when StartLine==EndLine, which is different from the ILAsm specification.

Suggested approach: My suggestion is to follow the ILAsm rules with the exception for EndColumn, where Portable PDB rule should be applied.

2. ilasm behavior on invalid .line directives

If a malformed .line directive is detected, ilasm rudely throws an error without generating the assembly file nor the PDB.

Suggested approach: In case of PDB generation errors ilasm should indeed refuse to generate the PDB file, but I think that assemblies should still be generated with a proper warning message indicating that the PDB generation has failed.

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Comments: 16 (16 by maintainers)

Most upvoted comments

I think 0xffff is reasonable as a workaround.

I think we should produce warning, but still emit the invalid sequence point (ie do not treat the warning as error).

It is a feature that ilasm can create invalid binaries. It is very useful for testing.