Skip to content

Commit

Permalink
Add Source file checksums in debug info section
Browse files Browse the repository at this point in the history
  • Loading branch information
arlosi committed Mar 19, 2020
1 parent 77600c0 commit c5dd2a4
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions src/debugging-support-in-rustc.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,36 @@ Focus is to let macros decide what to do. This can be achieved by having some ki
that lets the macro tell the compiler where the line marker should be. This affects where you
set the breakpoints and what happens when you step it.

## Source file checksums in debug info

Both DWARF and CodeView (PDB) support embedding a cryptographic hash of each source file that
contributed the associated binary.

The cryptographic hash can be used by a debugger to verify that the source file matches the
executable. If the source file does not match, the debugger can provide a warning to the user.

The hash can also be used to prove that a given source file has not been modified since it was
used to compile an executable. Because MD5 and SHA1 both have demonstrated vulnerabilities,
using SHA256 is recommended for this application.

#### DWARF 5
DWARF version 5 supports embedding an MD5 hash to validate the source file version in use.
DWARF 5 - Section 6.2.4.1 opcode DW_LNCT_MD5

#### LLVM
LLVM IR supports MD5, SHA1, and SHA256 source file checksums in the DIFile node.

LLVM DIFile documentation: [https://llvm.org/docs/LangRef.html#difile]

#### Microsoft Visual C++ Compiler /ZH option
The MSVC compiler supports embedding MD5, SHA1, or SHA256 hashes in the PDB using the `/ZH`
compiler option.

MSVC /ZH documentation: [https://docs.microsoft.com/en-us/cpp/build/reference/zh]

#### Clang
Clang always embeds an MD5 checksum, though this does not appear in documentation.

## Future work

#### Name mangling changes
Expand Down Expand Up @@ -295,10 +325,6 @@ They implement just the expression language but they also add some extensions li
convenience variables. Therefore, if you are taking this route then you not only need
to do this bridge but may have to add some mode to let the compiler understand some extensions.

#### Windows debugging (PDB) is missing

This is a complete unknown.

[Tom Tromey discusses debugging support in rustc]: https://www.youtube.com/watch?v=elBxMRSNYr4
[Debugging the Compiler]: compiler-debugging.md
[debugger or debugging tool]: https://en.wikipedia.org/wiki/Debugger
Expand Down

0 comments on commit c5dd2a4

Please sign in to comment.