@@ -268,6 +268,45 @@ Focus is to let macros decide what to do. This can be achieved by having some ki
268
268
that lets the macro tell the compiler where the line marker should be. This affects where you
269
269
set the breakpoints and what happens when you step it.
270
270
271
+ ## Source file checksums in debug info
272
+
273
+ Both DWARF and CodeView (PDB) support embedding a cryptographic hash of each source file that
274
+ contributed to the associated binary.
275
+
276
+ The cryptographic hash can be used by a debugger to verify that the source file matches the
277
+ executable. If the source file does not match, the debugger can provide a warning to the user.
278
+
279
+ The hash can also be used to prove that a given source file has not been modified since it was
280
+ used to compile an executable. Because MD5 and SHA1 both have demonstrated vulnerabilities,
281
+ using SHA256 is recommended for this application.
282
+
283
+ The Rust compiler stores the hash for each source file in the corresponding ` SourceFile ` in
284
+ the ` SourceMap ` . The hashes of input files to external crates are stored in ` rlib ` metadata.
285
+
286
+ A default hashing algorithm is set in the target specification. This allows the target to
287
+ specify the best hash available, since not all targets support all hash algorithms.
288
+
289
+ The hashing algorithm for a target can also be overridden with the ` -Z source-file-checksum= `
290
+ command-line option.
291
+
292
+ #### DWARF 5
293
+ DWARF version 5 supports embedding an MD5 hash to validate the source file version in use.
294
+ DWARF 5 - Section 6.2.4.1 opcode DW_LNCT_MD5
295
+
296
+ #### LLVM
297
+ LLVM IR supports MD5 and SHA1 (and SHA256 in LLVM 11+) source file checksums in the DIFile node.
298
+
299
+ [ LLVM DIFile documentation] ( https://llvm.org/docs/LangRef.html#difile )
300
+
301
+ #### Microsoft Visual C++ Compiler /ZH option
302
+ The MSVC compiler supports embedding MD5, SHA1, or SHA256 hashes in the PDB using the ` /ZH `
303
+ compiler option.
304
+
305
+ [ MSVC /ZH documentation] ( https://docs.microsoft.com/en-us/cpp/build/reference/zh )
306
+
307
+ #### Clang
308
+ Clang always embeds an MD5 checksum, though this does not appear in documentation.
309
+
271
310
## Future work
272
311
273
312
#### Name mangling changes
@@ -295,10 +334,6 @@ They implement just the expression language but they also add some extensions li
295
334
convenience variables. Therefore, if you are taking this route then you not only need
296
335
to do this bridge but may have to add some mode to let the compiler understand some extensions.
297
336
298
- #### Windows debugging (PDB) is missing
299
-
300
- This is a complete unknown.
301
-
302
337
[ Tom Tromey discusses debugging support in rustc ] : https://www.youtube.com/watch?v=elBxMRSNYr4
303
338
[ Debugging the Compiler ] : compiler-debugging.md
304
339
[ debugger or debugging tool ] : https://en.wikipedia.org/wiki/Debugger
0 commit comments