Repository navigation
Description
TL;DR: This lists the managed ilasm's PDB differences from native ilasm that the four PRs below do not address, numbered so they can be picked up one at a time. I am asking whether any of them are important to you; several items also ask a direct question. Nothing beyond those PRs is planned unless you name it.
While checking the managed ilasm's (src/tools/ilasm) PDB output against native ilasm and against src/tests/ilasm/PortablePdb, I found a number of differences. The PRs below address the ones that make that test suite fail. The rest are listed here, grouped and numbered, so they can be picked up one at a time.
What I am asking: are any of these important to you, or ones you would like to see addressed? Several items also ask a direct question. Nothing beyond the open PRs is planned unless you name it. I am happy to take whichever you point at, and to leave alone anything you consider intended or not worth a change.
Already addressed (open PRs, in landing order)
- Write the managed ilasm PDB to a separate file, as native ilasm does #135289: write the PDB as a separate
.pdbfile with CodeView, PdbChecksum and Reproducible entries. - Managed ilasm: per-point PDB documents, the input file and .line files as documents, LocalSignature row id #135297: per-point documents, the input file and every
.linefile as documents, theLocalSignaturerow id in the sequence-point blob header. - Managed ilasm: honour explicit local slots, scope local names lexically, and emit LocalScope/LocalVariable rows #135311: explicit local slots, lexical name scopes,
LocalScope/LocalVariablerows. - Managed ilasm: record sequence points as instructions are emitted, on the lines of the .il source when no .line directive is in effect #135312: sequence points recorded at instruction emission, on the
.ilsource when no.lineis in effect;#included files as documents.
Related issues: #135211 (PdbChecksum hashes only the #Pdb stream; -DET leaves the PDB id's stamp at 0), #135214 (-DET derives MVID, PE timestamp and PDB id from a zero-filled buffer), #135213 (ILLink leaves zero-length LocalScope rows), #46328 (end-column default of a partly specified .line).
Parity gaps in the managed tool
- 1.
#line(auto-increment) is parsed but the increment is never applied. Native's implementation is also broken (it increments the start line but not the end line, and then rejects its own sequence point), so this would be spec conformance rather than parity. PR: #136396. - 2. Partly specified
.linedirectives (ilasm throws an error when partly-defined .line directives are used #46328): native fails the assembly; managed emitsstart+1as the end column. The issue proposed0xffff. Should assembly fail, or should the end column bestart+1or0xffff? PR: #136396 (omitted end column defaults toushort.MaxValue - 1/65534for compatibility with existing SRM readers). - 3. Sequence points are not validated. Reversed line or column ranges reach the compressed-integer writer, which throws. A
0xFEEFEEstart line without0,0columns is treated as hidden. Columns of 0x10000 or more are encoded, although the format forbids them. Native warns and fails the method body. PR: #136396. Related SRM reader boundary corrections: #136403. - 4. A netmodule assembled with
-DEBUGgets noDebuggableAttribute; native attaches one viaAssemblyAttributesGoHere. The legacy two-BooleanDebuggableAttributeconstructor for a v1mscorlibtarget is not emitted either. PR: #136398. - 5. Non-deterministic PDB ids use the constant stamp
0x04030201; native uses the clock. ThePdbChecksumentry's timestamp is 0 (native: the PDB stamp). Overlaps with ilasm: PdbChecksum hashes only the #Pdb stream, and -DET leaves the PDB ID's stamp at 0 #135211. PR: #136399 (time-based nondeterministic PDB IDs; the checksum-entry timestamp remains zero per the SRM contract). - 6. A second
.entrypoint, or one on an instance method, is accepted silently; native reports an error. PR: #136402. - 7. With
-ERROR, native drops the rest of a method (and the following method) after a syntax error inside a body; managed keeps both methods, with the bad instruction emitting nothing. Which recovery is intended? PR: #136400 (preserve managed recovery; document and test the deliberate difference). - 8. Every diagnostic prints its location through the default
recordToString, so a single warning dumps the whole source text (74 lines forTestLocalScopes4.il, which triggers the in-use warning in both tools). Native printsfile(line) : warning : message. I would send a small PR forfile(line,col) : severity ILAxxxx : messageif that is wanted. PR: #136401. - 9. Integer literals are parsed as 64-bit and narrowed to 32-bit without a range check wherever the grammar takes an int32, so
4294967296reads as 0. The local-slot path checks the literal as written since Managed ilasm: honour explicit local slots, scope local names lexically, and emit LocalScope/LocalVariable rows #135311; the other consumers do not. PR: #136397. - Duplicate fields are not detected. (Duplicate fields should be allowed in error tolerant mode only)
Places where the managed tool is stricter than native
- 10. A
.linepath with single backslashes ('C:\p\win.cs') is a lexer error; native silently strips the backslashes (document nameC:pwin.cs). PR: #136400 (document and test the deliberate difference). - 11. A
.languageGUID without braces is accepted; native ignores it. PR: #136400 (document and test the deliberate difference).
Both look like improvements. Should they be listed in MANAGED-ILASM-FIXES.md as deliberate?
Native defects found on the way
No change to native is proposed; these are noted so the managed behaviour is not changed to match them. Each is already recorded as a deliberate difference in MANAGED-ILASM-FIXES.md by the PRs above.
-
EmitLocalslets an implicit local after[65535]take slot 65536, which no local instruction can name, and the PDB writer wraps itsLocalVariableindex to 0.[4294967295]is read as[-1]. A hexadecimal slot literal of more than 16 digits is read by its low bits. None of these gives a diagnostic. Already addressed/documented: #135311; no native change proposed.
-
- An instruction produced by a
#definemacro is mapped to line 1 (the macro text is lexed as a fresh source). After an#include, the including file still uses the.linefile named inside the included file, with the included file's coordinates. Already addressed/documented: #135312; no native change proposed.
- An instruction produced by a
Curiosity
- 14. The managed PDB is 4 bytes smaller than native's for every input with identical content. The measured cause is the
#USheap seed of the native metadata writer. No change proposed (Managed ilasm: remaining PDB differences from native ilasm after #135289, #135297, #135311 and #135312 #135314 (comment)).
Added 2026-10-07
- 15.
#includeresolution. Both tools resolve an#includepath as written, relative to the current directory, and both honour-INCLUDE. If those lookups fail, the managed tool also tries the path relative to the first input file's directory; native fails the include. An#includeinside an included file is resolved the same way as a top-level one in each tool, never relative to the including file. Is the input-directory fallback intended, and should it be listed inMANAGED-ILASM-FIXES.mdas deliberate? Should nested includes resolve relative to the including file, as C preprocessors do? (Measured against both tools, with the included file in the current directory, beside the input, or in both places, and with one level of nesting.) PR: #136400 (preserve current lookup behavior; document and test it).
Inputs, commands and dumps for each are available on request; tested on Linux x64 against main at 4a6440c3f03.
Note
This survey and this note were prepared with AI assistance (Anthropic Claude and OpenAI Codex) under my direction. AI agents ran the builds and probes on my machine. I reviewed the text before posting.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsNo status
Activity
dotnet-policy-service commentedon Oct 6, 2026
Tagging subscribers to this area: @dotnet/interop-contrib
See info in area-owners.md if you want to be subscribed.
dotnet-policy-service commentedon Oct 6, 2026
Tagging subscribers to this area: @JulieLeeMSFT, @dotnet/jit-contrib
See info in area-owners.md if you want to be subscribed.
pcshrosbree commentedon Oct 7, 2026
Point 14, measured. The four bytes are the
#US(user string) heap, and the cause is in the native metadata writer rather than in either PDB writer.#USheap00 03 20 00 00+ 3 padding00+ 3 paddingNative's heap holds the mandatory empty entry followed by one user string, a single space.
CLiteWeightStgdbRW::GetSaveSize(src/coreclr/md/enc/liteweightstgdbrw.cpp) adds it to any user-string heap that is still empty at save time, with the comment "An empty user string pool causes problems with edit and continue". Native ilasm saves the PDB through that same engine, and a PDB never has user strings, so every native PDB gets it. The same function adds a" "string to an empty#Stringsheap, underFEATURE_METADATA_EMIT_PORTABLE_PDB, "in order to be recognized by the VS debugger". That one fits in the heap's alignment padding (00 20 00 00against00 00 00 00), so it never shows as a size difference; it is in every native PDB whose#Stringsheap would otherwise be empty and absent once a local variable name is in the heap.Why native needs them: its pool-saving step skips a pool with no data ("If there is no data, then don't bother"), so without the seeds the
#USand#Stringsstreams would be missing from the file. The managed ilasm writes through System.Reflection.Metadata, which emits the heap streams even when they hold only the empty entry; a Roslyn-built PDB has the same 4-byte#USheap.Which is right: both are structurally valid. ECMA-335 lets a writer omit or keep an empty heap and allows unreferenced entries, and the Portable PDB spec requires only the
#Pdband#~streams. The debugging tables never reference#US. The readers in this repository (MetadataReader,PortablePdbSymbolReader,StackTraceSymbols) do not depend on the#Stringsseed either; I have not tested Visual Studio against a PDB whose#Stringsheap is empty, which is what native's comment is about. I would leave the managed output as it is. No change proposed.Evidence (Linux x64; native ilasm built from
main, managed at22a31f5c325, #135312's head): 35 inputs, each assembled by both tools from the same directory with the same input path and output name. 30 produced a PDB from both tools; native rejected four (the#lineand partial.lineinputs of items 1 and 2, and one.line-only input) and one failed in my harness over an include path. The two PDBs of each pair were compared stream by stream, the#Pdbstream after its 20-byte id, which always differs. In all 30 the#USheaps are exactly the two byte strings above. 27 of the 30 PDBs differ in size by exactly 4 bytes. The other three: two#includeinputs where native keeps a Document row for an included file that has no sequence point of its own (the deliberate difference listed in #135312), and a netmodule, whose native#Pdbstream records theMemberRefandCustomAttributerow counts of theDebuggableAttributenative attaches to a netmodule (item 4). As a check on the mechanism, an input withldstr "x"gives DLLs whose#USheaps agree in size, because native does not seed a non-empty heap, and PDBs that are still 4 bytes apart.For anyone comparing the two PDBs byte for byte, the streams of equal size are not byte-identical, for these reasons: the
Sortedmask in the#~header (native also marks absent type-system tables as sorted; System.Reflection.Metadata's PDB writer marks the present sorted debugging tables); theTypeRefrow count in#Pdb, which mirrors the DLL, where the managed tool emits aTypeReftoSystem.ValueTypein 24 of the 30 inputs through the lookup in its unsealed-type check (GrammarActions.Types.Headers.cs), unreferenced when the type extendsObject; the order of local names in#Stringsin two inputs; the separator byte of a document name with no directory part (native 0, managed/, same name); and the stream order (managed writes#Pdbfirst, native last). In the DLL, not the PDB, strings emitted through native'sDefineUserStringget a trailing flag byte of 1 ("This byte is not used by the runtime"), where System.Reflection.Metadata computes it as ECMA-335 II.24.2.4 specifies. TheValueTypereference and the trailing byte are DLL matters; I can add them as rows here if you want them tracked.Note
This measurement and this note were prepared with AI assistance (Anthropic Claude and OpenAI Codex) under my direction. AI agents ran the probes on my machine. I reviewed the text before posting.
pcshrosbree commentedon Oct 7, 2026
Added item 15 to the list above:
#includeresolution. The managed tool resolves an include relative to the current directory and then, unlike native, relative to the first input file's directory; neither tool resolves a nested include relative to the including file. Two questions are in the item. Nothing in the open PRs depends on the answer.Note
This note was prepared with AI assistance (Anthropic Claude) under my direction. I reviewed the text before posting.
Managed ilasm: per-point PDB documents, the input file and .line file…
Managed ilasm: honour explicit local slots, scope local names lexical…
jkoritzinsky commentedon Oct 22, 2026
@pcshrosbree to confirm, all of the above issues are all still around after your PRs?
Are you planning on sending PRs? (only asking as otherwise I will look into fixing them).
2 remaining items
pcshrosbree commentedon Oct 22, 2026
@jkoritzinsky, one more offer: once you have said which items you want to take, I can open a separate issue for each item that is still open. Each issue would describe exactly what its item needs, so it can be discussed and closed on its own. I'll wait for your answer before opening any.
jkoritzinsky commentedon Oct 23, 2026
@pcshrosbree I know I said I was going to ask you to do the work, but I ended up doing a decent amount of it myself for one reason or another. I'll put out PRs.
pcshrosbree commentedon Oct 23, 2026
@jkoritzinsky No problem at all. You weren't blocking me; I was just trying to help. The options I listed still stand, but I won't take any action until you tell me what you'd like. Let me know if you need anything from me.
jkotas commentedon Oct 24, 2026
Added point about duplicate fields
Managed ilasm: use time-based nondeterministic PDB IDs in nondetermin…
Managed ilasm: reject out-of-range int32 literals (#136397)
Managed ilasm: document and test deliberate behavior differences (#13…
Managed ilasm: support netmodule and legacy debug attributes (#136398)
Managed ilasm: format diagnostics with source coordinates (#136401)
Managed ilasm: validate method entry points (#136402)
Managed ilasm: apply #line increments and validate sequence points (#…
Managed ilasm: validate duplicate field declarations (#136526)
jkoritzinsky commentedon Oct 28, 2026
Fixed through various different PRs. Closing as completed.
pcshrosbree commentedon Oct 29, 2026
Thank you for fixing these and closing this out!