[metadata] Size 0 Blob heap is ok when resolving assembly refs (#18313)
commit07fee8a91dbc172bacded9d2c7f7d158eb7c50f1
authorAleksey Kliger (λgeek) <alklig@microsoft.com>
Fri, 3 Jan 2020 15:42:44 +0000 (3 10:42 -0500)
committerGitHub <noreply@github.com>
Fri, 3 Jan 2020 15:42:44 +0000 (3 10:42 -0500)
tree1a6e03469830b28a4515bf532553820a68b085ae
parent22afdb80e1b1921a66cb30c2a885bf0041cf67f1
[metadata] Size 0 Blob heap is ok when resolving assembly refs (#18313)

* [metadata] Size 0 Blob heap is ok when resolving assembly refs

Sometimes ILasm can produce images with a Blob heap of size 0.  In cases where
we're loading assembly references from such an image, the hash (which is
optional) can be at index = 0 and the Blob heap size is also 0.

Also: add the hash value to the output of `monodis --assemblyref`

* [metadata] Add a separate assertion for the index == size == 0 case

And a comment explaining how it is likely to be triggered.  If the assembly is
reasonable the caller of mono_metadata_blob_heap should be updated to use
mono_metadata_blob_heap_null_ok instead

* [bcl] Allow Mono's ILASM to produce a size 0 Blob heap

ECMA 335 II.24.2.4 says that the user string and blob heaps should have an
entry at index 0 consisting of the single byte 0.  However .NET Framework (and
.NET Core) ilasm will entirely omit the Blob heap (that is, create a blob heap
entry of size 0) if it is not needed.  This PR changes Mono's ILASM to emit the
initial byte on demand only if one of the MetaDataStream.Add() methods is
called. Otherwise we will also emit a stream of size 0.

This is needed to compile some test cases.

* [tests] Add regression test for loading assemblies with size 0 Blob heap

Depends on ILASM that can emit a size 0 Blob heap
mcs/class/PEAPI/Metadata.cs
mono/dis/dump.c
mono/metadata/assembly.c
mono/metadata/metadata-internals.h
mono/metadata/metadata.c
mono/tests/Makefile.am
mono/tests/null-blob-main.cs [new file with mode: 0644]
mono/tests/null-blob-null-blob-assm.il [new file with mode: 0644]
mono/tests/null-blob-ref.il [new file with mode: 0644]
mono/tests/null-blob-tgt.cs [new file with mode: 0644]