-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement SanitizerCoverage support (Refs. #6513) #6517
Conversation
Hmm, looks like the test needs to be less fragile. Will look into that. |
ab8fc5d
to
b312eee
Compare
Please refer to https://clang.llvm.org/docs/SanitizerCoverage.html TLDR: `ModuleSanitizerCoveragePass` instruments the IR by inserting calls to callbacks at certain constructs. What the callbacks should do is up to the implementation. They are effectively required for fuzzing to be effective, and are provided by e.g. libfuzzer. One huge caveat is `SanitizerCoverageOptions` which controls which which callbacks should actually be inserted. I just don't know what to do about it. Right now i have hardcoded the set that would have been enabled by `-fsanitize=fuzzer-no-link`, because the alternative, due to halide unflexibility, would be to introduce ~16 suboptions to control each one.
Just so you know, there's no need to force push... we always squash-merge our PRs and the history can be useful for review. |
Requesting reviews from @steven-johnson since he's familiar with the sanitizer stuff and from @zvookin since he will have opinions on how to deal with passing options to this. |
Thanks!
|
I think that's probably fine for the time being -- we can expand and add flexibility in the future as desired. That said, we should add a tracking issue here ("Target::SanitizerCoverage only supports equivalent of fuzzer-no-link") and add a link to it in comments at the relevant sites in the code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some nits re: style and comments, otherwise LGTM pending green
src/Module.cpp
Outdated
@@ -846,6 +846,7 @@ void compile_multitarget(const std::string &fn_name, | |||
Target::MSAN, | |||
Target::NoRuntime, | |||
Target::TSAN, | |||
Target::SANCOV, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
annoying style nit: all-caps SANCOV
seems out of place here as an all-caps abbreviation, despite MSAN, etc, since the latter are commonly referred to that way in LLVM docs but the former seems to be SanitizerCoverage
. If we are using this only for testing purposes then I think we should use either SanitizerCoverage
or sanitizer_coverage
to fit in with existing patterns. (Tagging @abadams here for his opinion as well.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO SanitizerCoverage to match the llvm docs, but I don't feel strongly about it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want me to change all instances of SANCOV to SanitizerCoverage, or just some?
If we are using this only for testing purposes
I'm not sure what you mean by that? Roughly, the feature will be requested the way it is requested in the test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change all instances of SANCOV to SanitizerCoverage, or just some?
I'd vote for all (except the ones in HalideRuntime.h, which should be sanitizer_coverage
to match the conventions there)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, let me know if i did it wrong.
src/Target.cpp
Outdated
@@ -384,7 +384,7 @@ const std::map<std::string, Target::Feature> feature_name_map = { | |||
{"llvm_large_code_model", Target::LLVMLargeCodeModel}, | |||
{"rvv", Target::RVV}, | |||
{"armv81a", Target::ARMv81a}, | |||
{"sancov", Target::SANCOV}, | |||
{"sanitizercoverage", Target::SanitizerCoverage}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"sanitizer_coverage", so that it matches the name in HalideRuntime.h
src/Target.cpp
Outdated
@@ -422,7 +422,7 @@ Target get_jit_target_from_environment() { | |||
host.set_feature(Target::TSAN); | |||
#endif | |||
#if __has_feature(coverage_sanitizer) | |||
host.set_feature(Target::SANCOV); | |||
host.set_feature(Target::SANITIZERCOVERAGE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like it won't compile, did you mean Target::SanitizerCoverage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did verify that this builds for me, starting with clean build dir.
Right, thanks, i didn't test-build halide with sancov.
src/Target.cpp
Outdated
@@ -1037,7 +1037,7 @@ bool Target::get_runtime_compatible_target(const Target &other, Target &result) | |||
} | |||
|
|||
if ((features & matching_mask) != (other.features & matching_mask)) { | |||
Internal::debug(1) << "runtime targets must agree on SoftFloatABI, Debug, TSAN, ASAN, MSAN, HVX, HexagonDma, HVX_shared_object, SANCOV\n" | |||
Internal::debug(1) << "runtime targets must agree on SoftFloatABI, Debug, TSAN, ASAN, MSAN, HVX, HexagonDma, HVX_shared_object, SANITIZERCOVERAGE\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SanitizerCoverage
@@ -2,12 +2,12 @@ | |||
|
|||
namespace { | |||
|
|||
class SANCOV : public Halide::Generator<SANCOV> { | |||
class SANITIZERCOVERAGE : public Halide::Generator<SANITIZERCOVERAGE> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/SANITIZERCOVERAGE/SanitizerCoverage/ or really anything that isn't ALLCAPS
public: | ||
Output<Buffer<int8_t>> output{"output", 3}; | ||
|
||
void generate() { | ||
// Currently the test just exercises Target::SANCOV | ||
// Currently the test just exercises Target::SANITIZERCOVERAGE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Target::SanitizerCoverage
@@ -16,10 +16,10 @@ class SANCOV : public Halide::Generator<SANCOV> { | |||
} | |||
|
|||
private: | |||
// Currently the test just exercises Target::SANCOV | |||
// Currently the test just exercises Target::SANITIZERCOVERAGE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Target::SanitizerCoverage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fixes!
@alexreinking @steven-johnson Thank you! |
Please refer to https://clang.llvm.org/docs/SanitizerCoverage.html
TLDR:
ModuleSanitizerCoveragePass
instruments the IR by insertingcalls to callbacks at certain constructs. What the callbacks should do
is up to the implementation. They are effectively required for fuzzing
to be effective, and are provided by e.g. libfuzzer.
One huge caveat is
SanitizerCoverageOptions
which controlswhich which callbacks should actually be inserted.
I just don't know what to do about it. Right now i have hardcoded
the set that would have been enabled by
-fsanitize=fuzzer-no-link
,because the alternative, due to halide unflexibility,
would be to introduce ~16 suboptions to control each one.