Skip to content

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

Open
elinor-fung with Copilot wants to merge 8 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 8 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
}
MSDiaSymbolReader reader = new MSDiaSymbolReader(args[0]);

string? pdbFile = null;

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.

@copilot We can still require the pdb file to be args[0] (like it did before)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done — the PDB file is back to args[0], with --image and symbol names parsed from the remaining args.

Note

This comment was generated by GitHub Copilot.

Comment thread src/coreclr/tools/PdbChecker/Program.cs Outdated
/// match the CodeView / RSDS debug record embedded in the output image. This guards
/// against native PDBs whose identity does not satisfy the image's symbol-server lookup key.
/// </summary>
private static void ValidatePdbMatchesImage(MSDiaSymbolReader reader, string imageFile)

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.

@copilot can we just make MSDiaSymbol reader use loadAndValidateDataFromPdb if we have an image?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. MSDiaSymbolReader now reads the image's CodeView/RSDS GUID+age and calls loadAndValidateDataFromPdb when an image is provided, so DIA performs the identity match (and rejects the all-zero-GUID PDB) instead of comparing manually in Program.cs.

Note

This comment was generated by GitHub Copilot.

…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 on lines +36 to +46
/// <summary>
/// PDB-info identity GUID as reported by DIA for the PDB file.
/// </summary>
public Guid PdbGuid { get; }

/// <summary>
/// PDB-info age as reported by DIA for the PDB file.
/// </summary>
public uint PdbAge { get; }

public MSDiaSymbolReader(string pdbFile, string? imageFile = null)

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.

@copilot remove these properties. All we do is print out the GUID and age in the constructor.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed the PdbGuid/PdbAge properties; the GUID and age are now local variables printed in the constructor (809f5c6).

Note

This comment was generated by GitHub Copilot.

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 on lines 78 to 85
Console.WriteLine("PDB file: {0}", pdbFile);
Console.WriteLine("PDB GUID: {0}", pdbGuid);
IDiaSymbol globalScope = _diaSession.globalScope;
Console.WriteLine("PDB file: {0}", pdbFile);
Console.WriteLine("PDB GUID: {0}", globalScope.guid);
Console.WriteLine("PDB age: {0}", globalScope.age);
Console.WriteLine("Total symbols: {0}", symbolsTotal);
Console.WriteLine("Public symbols: {0}", _pdbSymbols.Count);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-crossgen2-coreclr only use for closed issues

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

4 participants