This is an archive of the discontinued LLVM Phabricator instance.

Recommit "[libFuzzer] Disable implicit builtin knowledge about memcmp-like functions when -fsanitize=fuzzer-no-link is given."
ClosedPublic

Authored by dokyungs on Jul 16 2020, 2:31 PM.

Details

Summary

This patch disables implicit builtin knowledge about memcmp-like functions when compiling the program for fuzzing, i.e., when -fsanitize=fuzzer(-no-link) is given. This allows libFuzzer to always intercept memcmp-like functions as it effectively disables optimizing calls to such functions into different forms. This is done by adding a set of flags (-fno-builtin-memcmp and others) in the clang driver. Individual -fno-builtin-* flags previously used in several libFuzzer tests are now removed, as it is now done automatically in the clang driver.

The patch was once reverted in 8ef9e2bf355d05bc81d8b0fe1e5333eec59a0a91, as this patch was dependent on a reverted commit f78d9fceea736d431e9e3cbca291e3909e3aa46d. This reverted commit was recommitted in 831ae45e3dc609e43ba561af07670a8fe47461ef, so relanding this dependent patch too.

Diff Detail

Event Timeline

dokyungs created this revision.Jul 16 2020, 2:31 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJul 16 2020, 2:31 PM
Herald added subscribers: Restricted Project, cfe-commits. · View Herald Transcript
dokyungs edited the summary of this revision. (Show Details)Jul 16 2020, 2:34 PM
hctim accepted this revision.Jul 16 2020, 2:51 PM

LGTM w/ nit

clang/lib/Driver/SanitizerArgs.cpp
1091

Nit - add a comment here mentioning the libfuzzer interceptors, and that other sanitizers normally do this by propagating IR attributes.

This revision is now accepted and ready to land.Jul 16 2020, 2:51 PM
dokyungs updated this revision to Diff 278610.Jul 16 2020, 3:00 PM

Addressed comments.

dokyungs marked an inline comment as done.Jul 16 2020, 3:01 PM

Thanks Mitch for the comment! Added a comment that explains that.

hctim added inline comments.Jul 16 2020, 3:07 PM
clang/lib/Driver/SanitizerArgs.cpp
1092

I'd say "the following -fno-builtin-* flags force the compiler to emit interposable libcalls to these functions"

dokyungs updated this revision to Diff 278613.Jul 16 2020, 3:10 PM

Adjusted the comment as suggested.

dokyungs marked an inline comment as done.Jul 16 2020, 3:10 PM
hctim accepted this revision.Jul 16 2020, 3:39 PM

LGTM

This revision was automatically updated to reflect the committed changes.
dokyungs reopened this revision.Jul 24 2020, 9:57 AM
This revision is now accepted and ready to land.Jul 24 2020, 9:57 AM
dokyungs updated this revision to Diff 280507.Jul 24 2020, 9:57 AM

Relanding this reverted commit. (See summary)

dokyungs retitled this revision from [libFuzzer] Disable implicit builtin knowledge about memcmp-like functions when -fsanitize=fuzzer-no-link is given. to Recommit "[libFuzzer] Disable implicit builtin knowledge about memcmp-like functions when -fsanitize=fuzzer-no-link is given.".Jul 24 2020, 9:58 AM
dokyungs edited the summary of this revision. (Show Details)
dokyungs updated this revision to Diff 280981.Jul 27 2020, 11:06 AM

Add '-fno-builtin-bcmp' and a corresponding test case.

dokyungs updated this revision to Diff 280982.Jul 27 2020, 11:07 AM

Disable noasan-bcmp.test on darwin.

This revision was automatically updated to reflect the committed changes.