Skip to content
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

Merged
merged 8 commits into from
Jan 4, 2022

Conversation

LebedevRI
Copy link
Contributor

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.

@alexreinking alexreinking added enhancement New user-visible features or improvements to existing features. release_notes For changes that may warrant a note in README for official releases. usability labels Dec 28, 2021
@LebedevRI
Copy link
Contributor Author

Hmm, looks like the test needs to be less fragile. Will look into that.

@LebedevRI LebedevRI force-pushed the sancov branch 6 times, most recently from ab8fc5d to b312eee Compare December 30, 2021 20:49
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.
@alexreinking
Copy link
Member

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.

@alexreinking
Copy link
Member

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.

@LebedevRI
Copy link
Contributor Author

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!
Re options: we basically only have two choices:

  • just add a single best-guess meta-feature, like done here, that hardcodes the set of coverage to enable,
  • or add ~16 features to toggle each option in SanitizerCoverageOptions struct.

@steven-johnson
Copy link
Contributor

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.

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.

Copy link
Contributor

@steven-johnson steven-johnson left a 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,
Copy link
Contributor

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.)

Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Contributor

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)

Copy link
Contributor Author

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},
Copy link
Contributor

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);
Copy link
Contributor

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

Copy link
Contributor Author

@LebedevRI LebedevRI Jan 3, 2022

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"
Copy link
Contributor

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> {
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Target::SanitizerCoverage

Copy link
Contributor

@steven-johnson steven-johnson left a 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!

@steven-johnson steven-johnson merged commit f11d820 into halide:master Jan 4, 2022
@LebedevRI
Copy link
Contributor Author

@alexreinking @steven-johnson Thank you!

@LebedevRI LebedevRI deleted the sancov branch January 4, 2022 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New user-visible features or improvements to existing features. release_notes For changes that may warrant a note in README for official releases. usability
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants