Big-endian fixes: various problems in ilasm #55349
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While debugging problems running the roslyn test suite, I noticed a few more big-endian problems in ilasm:
Byte-swap property and parameter default values of string type
Default values of string type are swapped to little-endian by the parser (
fieldInit
). This has to be done there since "bytearray" values (which are provided by the user in little-endian format) are also encoded as string type, so we won't be able to tell the two cases apart later. However, the MD layer expects default values of all types, including strings, to be in native byte order (they're swapped again on big-endian hosts inCMiniMdBase::SwapConstant
). In order to fix this mismatch, the default values of fields are already swapped yet another time by ilasm code inAssembler::EmitField
. However, that same problem exists for default values of parameters or properties. This patch adds an equivalent swap operation there.Prepare custom attribute blobs in little-endian byte order
Custom attribute blobs (as opposed to default values) are expected to be provided in little-endian order by the MD layer. This already works for attributes specifies as byte arrays. But for attributes specified as structured values, values of all types except strings are currently provided in native order by the parser -- this is because
serInit
shares most of its implementation withfieldInit
above. To fix this, I've added a new helperAppendFieldToCustomBlob
that copies a typed value over to the custom attribute blob, byte-swapping as necessary. There are also a couple of places where ilasm synthesizes attribute blobs; some of those had a few byte swaps missing as well (seeAsmMan::EmitDebuggableAttribute
and thePermissionDecl
constructor).Fix byte order of
ELEMENT_TYPE_TYPEDEF
typespec blobs and of VTable blobsThese two are unrelated to the above, just another set of instances where byte swaps were missing.