Skip to content

System.Reflection.Metadata does not allow RVA mapped fields to be reliably aligned to 8 byte boundaries #62313

Description

@davidwrighton

Description

System.Reflection.Metadata exposes an api (System.Reflection.PortableExecutable.ManagedPEBuilder.MappedFieldDataAlignment) which is supposed to represent the alignment that the MappedFieldData elements are held at. That value is a constant with a value of 8. However, the mapped field data is actually not reliably 8 byte aligned. Instead it appears to be 4 byte aligned. Reliable alignment behavior is necessary to allow Roslyn to properly align data from the upcoming CreateSpan<T> feature.

Reproduction Steps

Build a C# binary from the following source, and compile with various different compile options (64bit vs 32bit, debug vs release, etc.)

using System;

Console.WriteLine("🌄");

 class C {

 ReadOnlySpan<byte> M() {
    return new byte[] { 1, 2, 3 };
}

 uint[] N() {
    return new uint[] { 1, 2, 3 };
}
}

Expected behavior

Examine the binary with ildasm, and note that the first field rva's is not reliably aligned at an 8 byte boundary.

Actual behavior

Depending on the particular flags used to the compiler, the first field may only be 4 byte aligned.

Regression?

No

Known Workarounds

No response

Configuration

No response

Other information

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions