Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit d374be8

Browse files
authored
PDB Checksum Debug Directory Record Specification (#26912)
* PDB Checksum Debug Directory Record Specification * Hash zeroed PDB ID * Update PE-COFF.md * Update PE-COFF.md
1 parent 0441e32 commit d374be8

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

src/System.Reflection.Metadata/specs/PE-COFF.md

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ Guid and Age are used to match PE/COFF image with the associated PDB.
2727

2828
The associated .pdb file may not exist at the path indicated by Path field. If it doesn't the Path, Guid and Age can be used to find the corresponding PDB file locally or on a symbol server. The exact search algorithm used by tools to locate the PDB depends on the tool and its configuration.
2929

30-
If the containing PE/COFF file is deterministic the Guid field above and DateTimeStamp field of the directory entry are calculated deterministically based solely on the content of the associated .pdb file. Otherwise the value of Guid is random and the value of DateTimeStamp indicates the time and date that the debug data was created.
30+
If the containing PE/COFF file is deterministic the Guid field above and DateTimeStamp field of the directory entry are calculated deterministically based solely on the content of the associated .pdb file. Otherwise the value of Guid is random and the value of DateTimeStamp indicates the time and date that the debug data was created.
3131

32-
*Version Major=any, Minor=0x504d* of the data format has the same structure as above. The Age shall be 1. The format of the .pdb file that this PE/COFF file was built with is Portable PDB. The Major version specified in the entry indicates the version of the Portable PDB format. Together 16B of the Guid concatenated with 4B of the TimeDateStamp field of the entry form a PDB ID that should be used to match the PE/COFF image with the associated PDB (instead of Guid and Age). Matching PDB ID is stored in the #Pdb stream of the .pdb file.
32+
<a name="PortableCodeViewEntry"></a> *Version Major=any, Minor=0x504d* of the data format has the same structure as above. The Age shall be 1. The format of the .pdb file that this PE/COFF file was built with is Portable PDB. The Major version specified in the entry indicates the version of the Portable PDB format. Together 16B of the Guid concatenated with 4B of the TimeDateStamp field of the entry form a PDB ID that should be used to match the PE/COFF image with the associated PDB (instead of Guid and Age). Matching PDB ID is stored in the #Pdb stream of the .pdb file.
3333

3434
> A matching PDB may be found whose format is different than the format of the PDB the PE/COFF file was built with. This may happen when the original PDB file is [converted](http://github.com/dotnet/symreader-converter) to the other format without updating the PE/COFF file. This scenario is fully supported. A tool looking for the associated PDB shall determine the actual format of the found PDB based on the signature at the start of the PDB file. The tool may use the version in CodeView entry as a hint to prefer the original format over the converted one if both are available.
3535
@@ -65,3 +65,41 @@ UncompressedSize shall be greater than 0. Other values are reserved for future u
6565
The Major version specified in the entry indicates the version of the Portable PDB format. The Minor version indicates the version of the Embedded Portable PDB data format.
6666

6767
The value of Stamp field in the entry shall be 0.
68+
69+
### PDB Checksum Debug Directory Entry (type 19)
70+
71+
Stores crypto hash of the content of the symbol file the PE/COFF file was built with.
72+
73+
The hash can be used to validate that a given PDB file was built with the PE/COFF file and not altered in any way.
74+
75+
More than one entry can be present, in case multiple PDBs were produced during the build of the PE/COFF file (e.g. private and public symbols).
76+
77+
*Version Major=0x0001, Minor=0x0000* of the entry data format is following:
78+
79+
| Offset | Size | Field | Description |
80+
|:------------------|:--------------|:---------------|-------------------------------------------------------------------------|
81+
| 0 | 4 | Signature | 0x50, 0x44, 0x42, 0x43 (ASCII string: "PDBC") |
82+
| 4 | AlgNameLength | AlgorithmName | Zero-terminated UTF8 string. The name of the crypho hash algorithm. |
83+
| 4 + AlgNameLength | ChecksumSize | Checksum | Blob. Checksum of the PDB content. |
84+
85+
_AlgorithmName_ is the name of the crypto hash algorithm used to calculate the checksum. The name is case-sensitive.
86+
87+
Supported algorithm names include at least:
88+
89+
| AlgorithmName | ChecksumSize | Description |
90+
|:--------------|:-------------|:-------------------------------------------------------------------|
91+
| `SHA256` | 32 | The 256-bit secure hash algorithm. Standard: FIPS 180-2, FIPS 198. |
92+
| `SHA384` | 48 | The 384-bit secure hash algorithm. Standard: FIPS 180-2, FIPS 198. |
93+
| `SHA512` | 64 | The 512-bit secure hash algorithm. Standard: FIPS 180-2, FIPS 198. |
94+
95+
#### Portable PDB Checksum
96+
97+
If the symbol format is Portable PDB the checksum is calculated by hashing the entire content of the PDB file with the PDB ID set to 0 (20 zeroed bytes).
98+
99+
When validating that Portable PDB matches the debug directory record check that the checksums match and that the PDB ID match the data in the corresponding [Portable CodeView record](#PortableCodeViewEntry).
100+
101+
> Excluding the PDB ID allows the compiler to calculate a single hash of the PDB file content and use it to generate both deterministic PDB ID and PDB checksum.
102+
103+
#### Windows PDB Checksum
104+
105+
TODO

0 commit comments

Comments
 (0)