This is an archive of the discontinued LLVM Phabricator instance.

[libFuzzer][MSVC] Make Sanitizer Coverage MSVC-compatible
ClosedPublic

Authored by metzman on Jan 17 2019, 10:16 AM.

Details

Summary

Make Sanitizer Coverage work when compiled work when compiler-rt
is compiled with MSVC.

The previous solution did not work for MSVC because MSVC tried to
align the .SCOV$CZ section even though we used
declspec(align(1)) on its only symbol:
stop___sancov_cntrs.
Because the counter array is composed
of 1 byte elements, it does not always end on an 8 or 4 byte
boundary. This means that padding was sometimes added to
added to align the next section, .SCOV$CZ.
Use a different strategy now: instead of only instructing
the compiler not to align the symbol, make the section
one byte long by making its only symbol a uint8_t, so that
the linker won't try to align it.

Diff Detail

Repository
rL LLVM

Event Timeline

metzman created this revision.Jan 17 2019, 10:16 AM
metzman updated this revision to Diff 182337.Jan 17 2019, 10:25 AM
  • add __declspec(align(1) back to be safe
metzman edited the summary of this revision. (Show Details)Jan 17 2019, 10:26 AM
metzman updated this revision to Diff 182339.Jan 17 2019, 10:35 AM
  • formatting
metzman edited the summary of this revision. (Show Details)Jan 17 2019, 12:46 PM
metzman updated this revision to Diff 182376.Jan 17 2019, 12:48 PM
  • improve comment
metzman edited the summary of this revision. (Show Details)Jan 17 2019, 12:49 PM
metzman edited the summary of this revision. (Show Details)

Matt and Reid could you please take a look?

This is the last major change needed to support MSVC in libFuzzer.

I figured out that I needed to make this change by using dumpbin on sanitizer libraries.
Before this change, when compiled with MSVC I saw this:

.SCOV$CZ name
C0100040 flags
         8 byte align

even though I saw the section was 1 byte aligned when compiled with clang.
Now that I've made the change the section is 1 byte aligned.

I don't think I need the __declspec(align(1)) any more but I've kept it to be safe.
Also, I think only __stop__sancov_counters needs to be a uint8_t,
__stop__sancov_pcs can probably be anything because the pc table always ends on an address that
is a multiple of word size so no padding is ever added. However I've also made it a uint8_t for consistency.

metzman updated this revision to Diff 182427.Jan 17 2019, 6:07 PM
  • undo change made for testing
metzman retitled this revision from [libFuzzer][MSVC] Make Sanitizer Coverage instrumentation work to [libFuzzer][MSVC] Make Sanitizer Coverage MSVC-compatible.Jan 17 2019, 6:09 PM
metzman edited the summary of this revision. (Show Details)

Code looks fine to me, but I don't have enough Windows knowledge to to evaluate the approach. I'll let @rnk comment on that.

rnk accepted this revision.Jan 18 2019, 3:18 PM

lgtm

This revision is now accepted and ready to land.Jan 18 2019, 3:18 PM
This revision was automatically updated to reflect the committed changes.