Skip to content

Flush Crossgen2 R2R output stream before generating native PDB - #131607

Open
elinor-fung with Copilot wants to merge 9 commits into
mainfrom
copilot/crossgen2-fix-pdb-info-guid
Open

Flush Crossgen2 R2R output stream before generating native PDB#131607
elinor-fung with Copilot wants to merge 9 commits into
mainfrom
copilot/crossgen2-fix-pdb-info-guid

Conversation

Copilot AI commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Crossgen2-generated native PDBs (*.ni.pdb) had an all-zero PDB-info GUID after the migration from R2RPEBuilder to PEObjectWriter, so the PDB could not satisfy the DLL's symbol-server lookup key and msdl symbol lookup failed for .NET 11 preview SDK R2R symbols.

Root cause

In ReadyToRunObjectWriter.EmitReadyToRunObjects, the output FileStream was declared with a method-scoped using, so it stayed open while SymbolFileBuilder.SavePdb ran. SavePdbPdbWriter.WritePDBDataHelper reads the finished image back from disk (File.Copy(dllPath, ...)) to feed DIA. Since FileStream buffers writes until disposed, DIA read an incomplete on-disk image with a zeroed CodeView/RSDS GUID, producing a PDB whose identity didn't match the DLL.

Changes

  • ReadyToRunObjectWriter.cs: Scope the object emission in a nested using block so the stream is flushed and closed before any symbol file (PDB/PerfMap) reads the image from disk. Capture stream.Length inside the block for the map builder, which was the only remaining consumer of the open stream.
long outputFileSize;
using (FileStream stream = new FileStream(_objectFilePath, FileMode.Create))
{
    objectWriter.EmitObject(stream, _nodes, dumper: null, logger);
    outputFileSize = stream.Length;
}
// ... SavePdb / SavePerfMap now read a fully-flushed image

Notes

No regression test is added here: native PDB generation goes through DIA, which is Windows-only, and there is no cross-platform crossgen2 PDB test infrastructure to extend.

Copilot AI review requested due to automatic review settings July 30, 2026 18:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because there is no eligible user to bill. To allow Copilot reviews on bot-authored pull requests, enable direct organization billing in your organization's Copilot settings.

@azure-pipelines

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

The FileStream that ReadyToRunObjectWriter writes the R2R image into was
kept open (via a method-scoped `using`) while SymbolFileBuilder.SavePdb
read the image back from disk to generate the native PDB. Because the
FileStream buffers writes until disposed, the PDB writer could observe an
incomplete image with a zeroed CodeView/RSDS GUID, producing native PDBs
whose PDB-info GUID did not match the DLL. Close the stream (capturing the
file size for the map builder) before generating symbol files.

Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 30, 2026 18:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because there is no eligible user to bill. To allow Copilot reviews on bot-authored pull requests, enable direct organization billing in your organization's Copilot settings.

Copilot AI changed the title [WIP] Fix zero PDB-info GUID in Crossgen2-generated native PDBs Flush Crossgen2 R2R output stream before generating native PDB Jul 30, 2026
Copilot AI requested a review from elinor-fung July 30, 2026 18:16
@github-actions github-actions Bot added the area-crossgen2-coreclr only use for closed issues label Jul 30, 2026
@elinor-fung
elinor-fung marked this pull request as ready for review July 30, 2026 18:58
@azure-pipelines

Copy link
Copy Markdown
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.

@elinor-fung

Copy link
Copy Markdown
Member

No regression test is added here: native PDB generation goes through DIA, which is Windows-only, and there is no cross-platform crossgen2 PDB test infrastructure to extend.

@copilot We already have PdbChecker. Can we update that to also validate the PDB and image match?

Extend PdbChecker to optionally take the crossgen2 output image via a new
`--image <file>` argument. When supplied, it reads the image's CodeView/RSDS
debug record and verifies the DIA-reported PDB-info GUID/age is nonzero and
matches the image identity, regressing the zero-GUID native PDB bug. Wire the
crossgen2 R2R test PDB check to pass the output image.

Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 30, 2026 19:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because there is no eligible user to bill. To allow Copilot reviews on bot-authored pull requests, enable direct organization billing in your organization's Copilot settings.

Avoid silently skipping validation and returning success when a PDB file
argument is omitted but --image is supplied.

Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 30, 2026 19:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because there is no eligible user to bill. To allow Copilot reviews on bot-authored pull requests, enable direct organization billing in your organization's Copilot settings.

Copilot AI commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

No regression test is added here: native PDB generation goes through DIA, which is Windows-only, and there is no cross-platform crossgen2 PDB test infrastructure to extend.

@copilot We already ha...

Done. PdbChecker now takes an optional --image <file> argument: when supplied it reads the image's CodeView/RSDS debug record and verifies the DIA-reported PDB-info GUID/age is nonzero and matches the image identity, failing otherwise. The crossgen2 R2R test PDB check in CLRTest.CrossGen.targets now passes the output image, so this runs as a regression guard for the zero-GUID bug.

Note

This comment was generated by GitHub Copilot.

Comment thread src/coreclr/tools/PdbChecker/Program.cs Outdated
Comment thread src/coreclr/tools/PdbChecker/Program.cs Outdated
…taFromPdb

Keep the PDB file as the first positional argument. When --image is supplied,
MSDiaSymbolReader reads the image's CodeView/RSDS identity and loads the PDB via
DIA's loadAndValidateDataFromPdb, which throws when the PDB-info GUID/age don't
match the image (including the all-zero GUID regression), instead of comparing
identities manually in Program.cs.

Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 30, 2026 20:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because there is no eligible user to bill. To allow Copilot reviews on bot-authored pull requests, enable direct organization billing in your organization's Copilot settings.

Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 30, 2026 20:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because there is no eligible user to bill. To allow Copilot reviews on bot-authored pull requests, enable direct organization billing in your organization's Copilot settings.

Comment thread src/coreclr/tools/PdbChecker/MSDiaSymbolReader.cs Outdated
Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 30, 2026 20:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because there is no eligible user to bill. To allow Copilot reviews on bot-authored pull requests, enable direct organization billing in your organization's Copilot settings.

Comment thread src/coreclr/tools/PdbChecker/MSDiaSymbolReader.cs Outdated
Comment thread src/coreclr/tools/PdbChecker/MSDiaSymbolReader.cs Outdated
Comment thread src/coreclr/tools/PdbChecker/MSDiaSymbolReader.cs Outdated
Co-authored-by: Elinor Fung <elfung@microsoft.com>
Copilot AI review requested due to automatic review settings July 30, 2026 21:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot's findings

  • Files reviewed: 4/4 changed files
  • Comments generated: 1

Comment thread src/coreclr/tools/PdbChecker/MSDiaSymbolReader.cs Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 30, 2026 21:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot's findings

Comments suppressed due to low confidence (2)

src/tests/Common/CLRTest.CrossGen.targets:406

  • __PdbFile and __OutputFile are appended to the PdbChecker command without quoting. If the test layout path contains spaces (common on Windows agents), the --image argument (and even the PDB path) will be split and PdbChecker will validate the wrong file or fail to start. Quote both paths when composing the command.
            set __CheckPdbCommand=!__DotNet!
            set __CheckPdbCommand=!__CheckPdbCommand! "!CORE_ROOT!\PdbChecker\PdbChecker.dll"
            set __CheckPdbCommand=!__CheckPdbCommand! !__PdbFile! --image !__OutputFile! @(CheckPdbSymbol->'%22%(Identity)%22', ' ')
            echo "!__CheckPdbCommand!"

src/coreclr/tools/PdbChecker/MSDiaSymbolReader.cs:88

  • The constructor now reads/validates both the PDB and (optionally) an image file, but the catch block always wraps failures as "Error opening PDB file ...". If imageFile is missing/corrupt or has no CodeView record, the error message will misleadingly blame the PDB. Include the image path in the wrapped message when imageFile is provided.
        catch (Exception ex)
        {
            throw new Exception($"Error opening PDB file {pdbFile}", ex);
        }
  • Files reviewed: 4/4 changed files
  • Comments generated: 0 new

@jtschuster jtschuster added area-ReadyToRun and removed area-crossgen2-coreclr only use for closed issues labels Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Crossgen2-generated native PDBs have zero PDB-info GUID after ObjectWriter migration

5 participants