Page MenuHomePhabricator

[sancov] Use LLVM Support library JSON writer in favor of individual implementation

Authored by dgg5503 on Oct 9 2019, 6:04 PM.



In this diff, I've replaced the individual implementation of JSONWriter with json::OStream provided by llvm/Support/JSON.h.

Important Note: The output format of the JSON is considerably different compared to the original implementation. Important differences include:

  • New line for each entry in an array (should make diffs cleaner)
  • No space between keys and colon in attributed object entries.
  • Attributes with empty strings will now print the attribute name and a quote pair rather than excluding the attribute altogether

Examples of these differences can be seen in the changes to the sancov tests which compare the JSON output.

Patch by Douglas Gliner.

Diff Detail

Event Timeline

dgg5503 created this revision.Oct 9 2019, 6:04 PM
vitalybuka edited the summary of this revision. (Show Details)Oct 10 2019, 5:56 PM
vitalybuka accepted this revision.Oct 10 2019, 6:15 PM
This revision is now accepted and ready to land.Oct 10 2019, 6:15 PM
kcc added a comment.Oct 10 2019, 6:19 PM

I was actually hoping to get rid of this code entirely.
Why do you need this change?

In D68752#1705235, @kcc wrote:

I was actually hoping to get rid of this code entirely.
Why do you need this change?

Hi @kcc,

Are you referring to the JSON formatted coverage report or some other aspect of sancov? The original fix found at D51018 rev 2 essentially added support for Windows paths to This also required some changes to the JSON writer in sancov and sancov itself to ensure paths were properly normalized and escaped. I figured I might as well have sancov use the LLVM JSON support library to reduce maintenance and also fix any potential escaping issues for free. These changes branched from this suggestion.

The original reason for D51018 was to allow coverage dumped from libFuzzer using -dump-coverage to be viewed via when the binary was compiled on Windows and therefore had Windows paths in the debug info. This feature has since been deprecated in libFuzzer, however, I would argue these patches are still relevant since you can still dump coverage standalone using the sanitizer run-time (see here).

This revision was automatically updated to reflect the committed changes.