commit f37950549bca59330117cbb44943b1984ab98b2c from: Alex Zanegin <10143657+azanegin@users.noreply.github.com> via: Sergey Bronnikov date: Wed Jan 17 12:16:41 2024 UTC luzer: disable instrumentation of internal functions Before this commit, internal functions were marked with attributes to protect them from Address Sanitizer. This was meant that Clang still instrumented code with coverage collection, slowing down hot path AND unstabilizing fuzzing process by damaging real coverage target. Fixes #11 commit - 0179547ff0fefbc18aee2372d0fed63784e9b4dd commit + f37950549bca59330117cbb44943b1984ab98b2c blob - c40732f7974de9c042f41a65346e82dc73766783 blob + b2cb78a09071a5d4150c0f266d41669e9757419f --- CHANGELOG.md +++ CHANGELOG.md @@ -14,3 +14,7 @@ and this project adheres to [Semantic Versioning](http - Integration with libFuzzer's `FuzzedDataProvider`. - Examples with tests. - Documentation with usecases, API etc. + +### Changed + +- Disable coverage instrumentation of internal functions (#11). blob - 984ed6829d6733ae2bf7b3b9d942c865339bfbc9 blob + ce997d9f5722dd7003c7b8dd1e0453570d849ff8 --- luzer/macros.h +++ luzer/macros.h @@ -36,6 +36,37 @@ #define NO_SANITIZE_MEMORY #endif // __has_attribute -#define NO_SANITIZE NO_SANITIZE_ADDRESS NO_SANITIZE_MEMORY +/* + * NO_SANITIZE_COVERAGE disables coverage instrumentation for + * selected functions via the function attribute + * __attribute__((no_sanitize("coverage"))). + * This attribute may not be supported by other compilers, + * so it is used together with __has_feature(coverage_sanitizer). + * See: + * - https://clang.llvm.org/docs/SanitizerCoverage.html#disabling-instrumentation-with-attribute-no-sanitize-coverage + * - https://clang.llvm.org/docs/LanguageExtensions.html#has-feature-and-has-extension + * + * Support of __has_feature(coverage_sanitizer) was added + * in Clang 13 together with no_sanitize("coverage"). + * Prior versions of Clang support coverage instrumentation, + * but cannot be queried for support by the preprocessor. + */ +#ifdef __has_feature +#if __has_feature(coverage_sanitizer) +#define NO_SANITIZE_COVERAGE __attribute__((no_sanitize("coverage"))) +#else // __has_feature(coverage_sanitizer) +#warning "compiler does not support 'coverage_sanitizer' feature" +#warning "it still may have instrumentation, but no way to exclude +#warning "certain functions found" +#warning "if you proceed, your coverage may be polluted or broken" +#define NO_SANITIZE_COVERAGE +#endif // __has_feature(coverage_sanitizer) +#else // __has_feature +#warning "compiler does not provide __has_feature," +#warning "can't check presence of 'coverage_sanitizer' feature" +#endif // __has_feature + +#define NO_SANITIZE NO_SANITIZE_ADDRESS NO_SANITIZE_MEMORY NO_SANITIZE_COVERAGE + #endif // LUZER_MACROS_H_