Repository navigation
[NativeAOT] Emit managed thread-static storage layouts in Unix DWARF - #133636
max-charlamb wants to merge 4 commits into
Conversation
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib |
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
🟡 Changes recommended
Two moderate findings remain unresolved.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Adds synthetic Unix DWARF types for NativeAOT managed thread-static storage layouts.
Changes:
- Emits storage-relative thread-static field offsets.
- Preserves static declaration and location ordering.
- Keeps Windows static-field handling unchanged.
File summaries
| File | Summary | Findings |
|---|---|---|
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/UserDefinedTypeDescriptor.cs |
Generates synthetic thread-static DWARF types and maintains static-field ordering. | Moderate finding at line 729 (3 votes): add regression coverage. Moderate finding at line 704 (2 votes): suppress the invalid process-global thread-static location. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 2
- Review effort level: Lite
There was a problem hiding this comment.
🔵 Needs a closer look
Unresolved findings concern thread-static locations, synthetic type naming, and regression coverage.
Review details
Suppressed comments (3)
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/UserDefinedTypeDescriptor.cs:729
- Please add an automated regression assertion for the synthetic type and its field offsets, including a type that mixes thread-static and ordinary static fields. The existing DwarfDump smoke test only runs
llvm-dwarfdump --verify, so it would pass if the__type...DIE were missing or if declaration/location ordering paired a field with the wrong static descriptor.
EmitThreadStaticFieldRegionType(defType, threadStaticStorageFields);
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/UserDefinedTypeDescriptor.cs:705
- This still adds every thread-static field to the normal DWARF static-variable stream, so
DwarfStaticVariableInfo.Dumpemits a process-globalDW_OP_addr <__THREADSTATICS...>location. That expression can return the wrong value for the selected thread even though the synthetic layout type is present. Keep thread-static fields only in the synthetic layout (or otherwise suppress theirDW_TAG_variablelocation) while retaining ordinary static declarations.
fieldsDescs.Add(field);
staticsDescs.Add(staticDesc);
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/UserDefinedTypeDescriptor.cs:873
- Use the original
type(or pass the already-computedthreadStaticDataName) when naming this synthetic DIE.GetClassTypeIndexcan canonicalizetypeinto a differentdefTypefor high generic complexity, while the actual static descriptor is built fromThreadStatics(type)above; in that case the emitted__type<ThreadStatics(defType)>no longer matches the storage/index symbol fortype, so a diagnostic reader cannot associate the layout with the field storage.
Name = Utf8String.Concat(
"__type"u8,
NodeFactory.NameMangler.NodeMangler.ThreadStatics(defType).AsSpan()),
- Files reviewed: 1/1 changed files
- Comments generated: 0 new
- Review effort level: Lite
Add synthetic DWARF storage types with field offsets while retaining existing static metadata. Keep static declarations aligned with their location descriptors. Co-authored-by: Copilot <[email protected]> Copilot-Session: 4d2eff7d-b599-47c5-90d1-ee54e0e623f9
22d37c6 to
3f23eee
Compare
There was a problem hiding this comment.
🔵 Needs a closer look
Address the invalid thread-static location metadata and add semantic regression coverage.
Review details
Suppressed comments (2)
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/UserDefinedTypeDescriptor.cs:705
- Adding every thread-static field to the normal declaration/location stream still makes
DwarfClassTypeInfoemit aDW_TAG_variable, andDwarfStaticVariableInfo.Dumpgives it aDW_OP_addr <__THREADSTATICS...>expression. That address is process-global metadata rather than the selected thread's storage, so following the ordinary debugger variable can still read the wrong thread's value. Suppress this invalid value location (while preserving a declaration if compatibility requires it) and keep the field's offset in the synthetic layout type.
fieldsDescs.Add(field);
staticsDescs.Add(staticDesc);
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/UserDefinedTypeDescriptor.cs:729
- The new synthetic DIE and the declaration/location reordering are not covered by a checked-in semantic assertion. The existing
src/tests/nativeaot/SmokeTests/DwarfDumpprogram only runsllvm-dwarfdump --verifyand counts warnings/errors, so it would still pass if this type or a field offset were missing or paired with the wrong static location. Add a regression assertion for a type mixing thread-static and ordinary static fields.
EmitThreadStaticFieldRegionType(defType, threadStaticStorageFields);
- Files reviewed: 1/1 changed files
- Comments generated: 0 new
- Review effort level: Lite
Use the existing thread-static field collection for both Windows and Unix storage layout emission. Co-authored-by: Copilot <[email protected]> Copilot-Session: 572c5f77-8001-4916-b5d1-502c66b60415
|
Would this scheme work for both inlined and non-inlined thread statics? The compiler does thread statics differently based on whether this is a Debug/Release build ("we have scanner"), or whether this is X64/ARM64 vs anything else, or whether this is Linux/Windows vs anything else. (https://github.com/search?q=repo%3Adotnet%2Fruntime+noinlinetls&type=code). |
Yes. This works for both inlined and non-inlined thread statics. I have verified both locally. |
Emit Unix GC and non-GC static storage layouts alongside thread-static layouts, fix the GC static DWARF location dereference, and give Windows storage helper UDTs their actual sizes so DbgEng rejects missing members. Co-authored-by: Copilot <[email protected]> Copilot-Session: bdbe5d54-e32e-4939-82ef-6b5b850ee4e9
Advertise the updated static storage layouts and corrected field location metadata under a new contract version. Co-authored-by: Copilot <[email protected]> Copilot-Session: bdbe5d54-e32e-4939-82ef-6b5b850ee4e9

Summary
This PR fixes three related problems in NativeAOT static-field debug metadata: incorrect Unix DWARF locations, missing Unix storage-layout types, and zero-sized Windows storage-layout types.
These changes are advertised by NativeAOT
SymbolNamecontract versionn3(previouslyn2).1. Make ordinary GC and non-GC statics readable through DWARF
There were two problems with the existing location metadata:
This PR keeps declarations and location descriptors in the same order and removes the extra dereference. The resulting address calculations are:
2. Add Windows-style static storage layout types on Unix
Windows PDBs already contain synthetic types describing the fields within each type's static storage. This PR emits equivalent DWARF layout types on Unix for all three storage kinds:
These are debug types, not new runtime allocations or data symbols. Each contains the fields' storage-relative offsets and describes the size of the storage region. GC and thread-static layouts include their object base; non-GC layouts describe the non-object storage region.
The thread-static type supplies information that the existing static field declaration does not: the offset of a field within its thread-static storage. For example, on x64, the layout for
AsyncDispatcherInfodescribest_currentat offset8, after the method-table pointer.A diagnostic reader can resolve the existing per-type thread-static index, traverse storage for the selected thread, and then apply the offset from this new type. The GC/non-GC layout types allow ordinary statics to be read using the same storage-plus-field-offset model.
This does not make the legacy thread-static
DW_AT_locationexpressions thread-aware, change TLS storage, or copy the Windows Natvis wrapper onto Unix. Runtime-aware traversal is still required to locate a selected thread's storage.3. Emit actual Windows storage-layout sizes to avoid a DbgEng bug
The existing Windows emitter described complete static-storage helper types with size
0, even though they had fields.With these zero-sized types, DbgEng's
GetFieldOffsetcan returnS_OKand offset0for a field that does not exist. This makes a successful field lookup unreliable when determining whether a field belongs to GC or non-GC storage.This PR emits the actual GC, non-GC, and thread-static region sizes instead. This avoids the false-success behavior without changing member names, field offsets, or the separate
__ThreadStaticHelper<T>wrapper used by Natvis. Zero-sized forward declarations are unchanged.Validation
Related to #132237. This builds on the thread-static field-availability correction in #133109, which is already in
mainand is not part of this diff.