This is an archive of the discontinued LLVM Phabricator instance.

[libfuzzer] [clang] Add __has_feature(fuzzing_coverage)
AbandonedPublic

Authored by hctim on Jun 30 2020, 4:52 PM.

Details

Reviewers
morehouse
Dor1s
Summary

Probably a useful feature for checking whether a file was built with
-fsanitize=fuzzer or -fsanitize=fuzzer-no-link.

N.B. __has_feature(fuzzing_coverage) doesn't cover instances where users
manually specify -fsanitize-coverage=... (even if the flags are
identical to ToT -fsanitize=fuzzer-no-link). IMHO this is WAI -
-fsanitize=fuzzer-no-link is not a stable set of flags and people that
want sancov for fuzzing should use fuzzer-no-link.

Diff Detail

Event Timeline

hctim created this revision.Jun 30 2020, 4:52 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 30 2020, 4:52 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
hctim updated this revision to Diff 274656.Jun 30 2020, 4:59 PM

Changed the filename and fixed up the inverted test.

Can we just use [FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION](https://llvm.org/docs/LibFuzzer.html#fuzzer-friendly-build-mode) instead? I'm a little wary of introducing a new way to do conditional compilation since fuzzers that don't use sancov can't rely on it.

Dor1s added a comment.Jul 1 2020, 9:33 AM

What usecase(s) do you have for this in mind?

hctim added a comment.Jul 1 2020, 10:08 AM

So - the FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION flag is a property of the build system and not that of the compiler. There are some places (android) where enabling FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION globally changes the behaviour of large amounts of libraries in ways that break the build system.

Having this flag allows us to make targeted compile-time changes to libc based on sancov that don't require enabling FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION across the entire build system.

So - the FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION flag is a property of the build system and not that of the compiler. There are some places (android) where enabling FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION globally changes the behaviour of large amounts of libraries in ways that break the build system.

Having this flag allows us to make targeted compile-time changes to libc based on sancov that don't require enabling FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION across the entire build system.

Shouldn't we be fixing the fuzzing build for Android then? FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION is what we use everywhere else, so I don't like the idea of making a new flag.

Dor1s added a comment.Jul 1 2020, 10:34 AM

If we still decide to proceed with this, would it make sense to expand it to sanitizer_coverage based on any sancov instrumentation being enabled? As you mentioned in the description, there might be users who manually enable certain sancov flags. I think it's good to be able to support those usecases too (e.g. other fuzzing engines).

hctim abandoned this revision.May 23 2022, 3:46 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 23 2022, 3:46 PM