ILC fails to pre-initialize pointer fields to pre-initialized memory sections
- Dominant language
- C#
- Stars
- 18.3k
- Forks
- 5.6k
- PR merge metrics
- PR metrics pending
Description
### Description
I just noticed ILC fails to pre-initialize `ReferenceTracker` in the runtime:
https://github.com/dotnet/runtime/blob/e2a94a1b7a621ea9339ad4c4919d732b9f4aadf7/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/ReferenceTrackerHost.cs#L14
> "ILC: Could not preinitialize '[S.P.CoreLib]System.Runtime.InteropServices.ReferenceTrackerHost': Method '[S.P.CoreLib]System.Runtime.InteropServices.ReferenceTrackerHost..cctor()', opcode 'stsfld' Unsupported store"
Despite the fact that `HostServices.Vftbl` is correctly folded and ends up being a constant section in .rdata. I understand that ILC doesn't support pointers in a general way for pre-initialization, but it seems like it should be able to handle pointers to .rdata segments given it is definitely able to know the exact address of those ones, so this would just be the same as that?
It would also be fine if this needed to be restricted in some way (e.g. the field must be `nint`, or `void*` or whatever).
cc. @MichalStrehovsky
### Reproduction Steps
This exact bit:
https://github.com/dotnet/runtime/blob/e2a94a1b7a621ea9339ad4c4919d732b9f4aadf7/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/ReferenceTrackerHost.cs#L14
### Expected behavior
The `ReferenceTracker` field should be able to be pre-initialized.
### Actual behavior
The type is not pre-initialized.
### Regression?
No.
### Configuration
.NET 10 (.NET SDK 10.0.102)
Contributor guide
Assessment
This issue has not been assessed yet.