-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RuntimeHelpers.CreateSpan support is failing in some circumstances #79477
RuntimeHelpers.CreateSpan support is failing in some circumstances #79477
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
There's at least one issue here in the Roslyn support. When the data is the 2/4/8 bytes in size, today it uses the built-in system types (short, int, long), but we shouldn't be doing so when the alignment is > 1, as those types have a .pack of 1, and thus a rewriter may not align the resulting data correctly. EDIT: These were fixed in dotnet/roslyn#65919. It appears there may still be an additional issue beyond that, however, though I've only been able to repro the impact of the above locally. |
Tagging subscribers to this area: @dotnet/area-system-runtime-compilerservices Issue Detailsdotnet/roslyn#61414 updated Roslyn with the ability to target RuntimeHelpers.CreateSpan. #79461 updates dotnet/runtime to pull in a newer version of Roslyn that contains the improvements and updates a bunch of code to take advantage of CreateSpan. But CI for that is failing due to ArgumentExceptions coming from CreateSpan due to what appears to be alignment issues. @davidwrighton is investigating, and I'm opening this to track, as we may need to back the changes out of Roslyn if it's an issue with the runtime or linker...
|
We really should enforce this in the runtime and not wait for IL rewriters to break this - it was an unadressed piece of feedback when this was introduced: #63977 (comment). Roslyn using primitive types was specifically my example there :). |
@sbomer, seems likely there's a linker bug here. Some of the legs in #79461 are failing catastrophically with errors like:
I've attached the System.Private.CoreLib.zip binary from the failing
Note the address 001B881C, which is not 8-byte aligned. But the associated type does have a .pack of 8:
I can repro this locally. With the https://github.com/stephentoub/runtime/tree/usecreatespan branch, if I build with:
I get the same erroneously-aligned address. But if I then edit the .\src\coreclr\System.Private.CoreLib\System.Private.CoreLib.csproj file to change the: <ILLinkTrimAssembly>true</ILLinkTrimAssembly> to: <ILLinkTrimAssembly>false</ILLinkTrimAssembly> I then get an 8-byte-aligned address of 004602C0, which makes sense given Roslyn 8-byte aligns every RVA field. Can you take a look? cc: @davidwrighton, @jcouv |
Tagging subscribers to this area: @agocke, @sbomer, @vitek-karas Issue Detailsdotnet/roslyn#61414 updated Roslyn with the ability to target RuntimeHelpers.CreateSpan. #79461 updates dotnet/runtime to pull in a newer version of Roslyn that contains the improvements and updates a bunch of code to take advantage of CreateSpan. But CI for that is failing due to ArgumentExceptions coming from CreateSpan due to what appears to be alignment issues. @davidwrighton is investigating, and I'm opening this to track, as we may need to back the changes out of Roslyn if it's an issue with the runtime or linker...
|
This is a bug in Cecil. David's change to Cecil correctly sets the alignment for each field data blob and the minimum alignment necessary for the entire data blob. But when Cecil computes positions of each of the blobs, it incorrectly applies the alignment to the length of the blob, not to its position. I think the bug is basically here: https://github.com/dotnet/cecil/blob/49215988d4404e2c0befe697ce37a3f38e99953e/Mono.Cecil.PE/TextMap.cs#L54 It applies the alignment to the length, not position - it should probably do both. This affects only x86, on x64 the position will be aligned to 8 at least. |
Thanks!
Tests are failing in a similar way on arm64, e.g. |
IL blobs do not need to be aligned to more than 4. |
We may need to push this bug fix to servicing. This bug fix needs to be present in all places where the new Roslyn or packages built with new Roslyn can meet with ILLinker. |
It's hard to tell if the 16 align is because of the code blob, or the following Resources blob. But honestly given the behavior of the alignment I would not be surprised if it was broken in subtle ways in more than one place. |
Can we backport the fix for this to release/7.0? RuntimeHelpers.CreateSpan shipped in .NET 7, and a Roslyn compiler that lights up when it sees CreateSpan will be shipping supported soon, which means anyone who has the combination of conditions that can lead to this may immediately start seeing failures upon recompilation. I believe those conditions are the combination of:
|
The fix was backported to 7.0 in dotnet/cecil#61. |
dotnet/roslyn#61414 updated Roslyn with the ability to target RuntimeHelpers.CreateSpan. #79461 updates dotnet/runtime to pull in a newer version of Roslyn that contains the improvements and updates a bunch of code to take advantage of CreateSpan. But CI for that is failing due to ArgumentExceptions coming from CreateSpan due to what appears to be alignment issues. @davidwrighton is investigating, and I'm opening this to track, as we may need to back the changes out of Roslyn if it's an issue with the runtime or linker...
The text was updated successfully, but these errors were encountered: