Skip to content

JIT: Value-initialize regPtrDsc entries - #137506

Merged
jkotas merged 1 commit into
dotnet:mainfrom
am11:valgrind-fixes
Nov 14, 2026
Merged

jkotas merged 1 commit into
dotnet:mainfrom
am11:valgrind-fixes

Conversation

@am11

@am11 am11 commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Value-initialize regPtrDsc instead of resetting individual fields. This silences valgrind's uninitialized-value reports from the JIT's GC info encoding (CoreCLR app, Release, valgrind 3.26):

main PR
Uninitialized value reports 29 1

@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Nov 13, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 pipeline(s).
10 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib
See info in area-owners.md if you want to be subscribed.

@MichalStrehovsky

Copy link
Copy Markdown
Member

Does the out of bound read still happen with code in #137539 deleted? That code seems to be some relic from .NET Native times. If it still does something, it's probably papering over a bug (we'll see once the CI is done).

`gcRegPtrAllocDsc` allocated `regPtrDsc` from the arena and only reset a
few fields. Clang builds the bitfield byte from whatever was already in
memory and sets `rpdArg` with `and; inc`, which memcheck models as an
add that taints every bit above the lowest undefined input bit. As a
result valgrind reported `rpdGCtype` as uninitialized and the noise
propagated into the `StackSlotIdKey` hash table lookups and the GC slot
sort in the GC info encoder (29 reports for a small ASP.NET app).

Value-initialize the entry instead, which also covers the fields that
were reset explicitly. Generated code and GC info are unchanged.

Co-authored-by: Cursor <[email protected]>
@am11 am11 changed the title Record instantiation arg kind in fat fn pointers JIT: Value-initialize regPtrDsc entries Nov 14, 2026
@am11

am11 commented Nov 14, 2026

Copy link
Copy Markdown
Member Author

Confirmed: with #137539 the out-of-bounds read is gone. On the same main base, DynamicGenerics under valgrind goes from 27 "Invalid read of size 4" errors in TryGetStaticGenericMethodComponents (one context) to 0, and the NativeAOT smoke tests, including Reflection and UnitTests, still pass.

I've dropped the fat function pointer change and repurposed this PR for the other valgrind finding: the uninitialized-value reports from the JIT's GC info encoding.

@MichalStrehovsky MichalStrehovsky added area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI and removed area-NativeAOT-coreclr labels Nov 14, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

@jkotas

jkotas commented Nov 14, 2026

Copy link
Copy Markdown
Member

Where is the uninitialized read reported in the JIT?

This change will make it read 0, but that's is not necessarily the right fix - the value is still de-facto uninitialized.

@am11

am11 commented Nov 14, 2026

Copy link
Copy Markdown
Member Author

It's reported in gcMakeRegPtrTable (rpdGCtypeGet()), but there is no read of an unwritten field: every producer assigns rpdGCtype first. The bitfields share one storage unit, so each assignment is a read-modify-write that starts from stale arena memory, and memcheck flags that. Zeroing makes those writes start from defined memory and replaces the existing field-by-field resets; nothing is masked.

@jkotas jkotas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@jkotas

jkotas commented Nov 14, 2026

Copy link
Copy Markdown
Member

/ba-g s dead-letter

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

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants