Skip to content

Managed ilasm: remaining PDB differences from native ilasm after #135289, #135297, #135311 and #135312 #135314

Closed

Description

@pcshrosbree

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)

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 .line directives (ilasm throws an error when partly-defined .line directives are used #46328): native fails the assembly; managed emits start+1 as the end column. The issue proposed 0xffff. Should assembly fail, or should the end column be start+1 or 0xffff? PR: #136396 (omitted end column defaults to ushort.MaxValue - 1 / 65534 for compatibility with existing SRM readers).
  • 3. Sequence points are not validated. Reversed line or column ranges reach the compressed-integer writer, which throws. A 0xFEEFEE start line without 0,0 columns 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 -DEBUG gets no DebuggableAttribute; native attaches one via AssemblyAttributesGoHere. The legacy two-Boolean DebuggableAttribute constructor for a v1 mscorlib target is not emitted either. PR: #136398.
  • 5. Non-deterministic PDB ids use the constant stamp 0x04030201; native uses the clock. The PdbChecksum entry'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 record ToString, so a single warning dumps the whole source text (74 lines for TestLocalScopes4.il, which triggers the in-use warning in both tools). Native prints file(line) : warning : message. I would send a small PR for file(line,col) : severity ILAxxxx : message if 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 4294967296 reads 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 .line path with single backslashes ('C:\p\win.cs') is a lexer error; native silently strips the backslashes (document name C:pwin.cs). PR: #136400 (document and test the deliberate difference).
  • 11. A .language GUID 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.

    1. EmitLocals lets an implicit local after [65535] take slot 65536, which no local instruction can name, and the PDB writer wraps its LocalVariable index 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.
    1. An instruction produced by a #define macro is mapped to line 1 (the macro text is lexed as a fresh source). After an #include, the including file still uses the .line file named inside the included file, with the included file's coordinates. Already addressed/documented: #135312; no native change proposed.

Curiosity

Added 2026-10-07

  • 15. #include resolution. Both tools resolve an #include path 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 #include inside 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 in MANAGED-ILASM-FIXES.md as 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.

Activity

  1. added
    untriaged
    on Oct 6, 2026
  2. dotnet-policy-service commented on Oct 6, 2026

    @dotnet-policy-service
    Contributor

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

  3. dotnet-policy-service commented on Oct 6, 2026

    @dotnet-policy-service
    Contributor

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

  4. pcshrosbree commented on Oct 7, 2026

    @pcshrosbree
    ContributorAuthor

    TL;DR: The four-byte difference in point 14 is the #US heap: native's metadata writer adds a one-space user string to a user-string heap that is still empty at save time, so every native PDB gets it. Both outputs are structurally valid, and I would leave the managed output as it is; no change is proposed. The evidence and the other byte-level differences between the two PDBs follow.

    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.

    native PDB managed PDB
    #US heap 8 bytes: 00 03 20 00 00 + 3 padding 4 bytes: 00 + 3 padding
    every other stream same size (in 27 of the 30 pairs below) same size

    Native'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 #Strings heap, under FEATURE_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 00 against 00 00 00 00), so it never shows as a size difference; it is in every native PDB whose #Strings heap 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 #US and #Strings streams 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 #US heap.

    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 #Pdb and #~ streams. The debugging tables never reference #US. The readers in this repository (MetadataReader, PortablePdbSymbolReader, StackTraceSymbols) do not depend on the #Strings seed either; I have not tested Visual Studio against a PDB whose #Strings heap 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 at 22a31f5c325, #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 #line and partial .line inputs 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 #Pdb stream after its 20-byte id, which always differs. In all 30 the #US heaps are exactly the two byte strings above. 27 of the 30 PDBs differ in size by exactly 4 bytes. The other three: two #include inputs 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 #Pdb stream records the MemberRef and CustomAttribute row counts of the DebuggableAttribute native attaches to a netmodule (item 4). As a check on the mechanism, an input with ldstr "x" gives DLLs whose #US heaps 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 Sorted mask in the #~ header (native also marks absent type-system tables as sorted; System.Reflection.Metadata's PDB writer marks the present sorted debugging tables); the TypeRef row count in #Pdb, which mirrors the DLL, where the managed tool emits a TypeRef to System.ValueType in 24 of the 30 inputs through the lookup in its unsealed-type check (GrammarActions.Types.Headers.cs), unreferenced when the type extends Object; the order of local names in #Strings in two inputs; the separator byte of a document name with no directory part (native 0, managed /, same name); and the stream order (managed writes #Pdb first, native last). In the DLL, not the PDB, strings emitted through native's DefineUserString get 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. The ValueType reference 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.

  5. pcshrosbree commented on Oct 7, 2026

    @pcshrosbree
    ContributorAuthor

    Added item 15 to the list above: #include resolution. 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.

  6. removed
    untriaged
    on Oct 9, 2026
  7. added this to the 12.0.0 milestone on Oct 9, 2026
  8. jkoritzinsky commented on Oct 22, 2026

    @jkoritzinsky
    Member

    @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).

  9. 2 remaining items

  10. pcshrosbree commented on Oct 22, 2026

    @pcshrosbree
    ContributorAuthor

    @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.

  11. jkoritzinsky commented on Oct 23, 2026

    @jkoritzinsky
    Member

    @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.

  12. pcshrosbree commented on Oct 23, 2026

    @pcshrosbree
    ContributorAuthor

    @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.

  13. jkotas commented on Oct 24, 2026

    @jkotas
    Member

    Added point about duplicate fields

  14. jkoritzinsky commented on Oct 28, 2026

    @jkoritzinsky
    Member

    Fixed through various different PRs. Closing as completed.

  15. pcshrosbree commented on Oct 29, 2026

    @pcshrosbree
    ContributorAuthor

    Thank you for fixing these and closing this out!

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

Metadata

Metadata

Assignees

Type

No type

Projects

  • Status
    No status

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions