ASan Support#3918
Conversation
|
|
||
| #if defined(__has_feature) | ||
| #if __has_feature(address_sanitizer) | ||
| #define GIT_ASAN 1 |
There was a problem hiding this comment.
I'm not sure I understand what's going on here. When is __has_feature(address_sanitizer) true? It seems like it's true when address_sanitizer is available, not when libgit2 was built with it, no?
If your goal is to provide some functionality to callers about whether libgit2 was built with address_sanitizer, then please have cmake set -DGIT_ASAN and expose a function that will check and return that. (Probably a query key on git_libgit2_opts makes sense.)
There was a problem hiding this comment.
The feature is enabled when AddressSanitizer is available and currently being used for the current compile run.
The CMake modules take care of automatically passing in the correct flags to the compiler when you -DASAN=ON, which will in turn cause that define to exist. The ultimate goal is to be able to tell at compile-time whether ASan is enabled or not (because the modules don't set anything since there's a clang feature macro for it), so we can skip the oom test below (e.g. doing weird things that makes ASan unhappy, like allocating the whole memory). That's the only point of it actually, so if having that in common.h feels wrong, I can move it somewhere else.
I don't really get the point about providing functionality. Because ASan incurs a typical 2x slowdown, it's not something I expect to be queried at runtime. It can be used as a debugging tool (build libgit2 with ASan, link your app with that version, run and wait).
There was a problem hiding this comment.
Got it - yeah, I don't think that a public header is the best place for this. I would suggest src/common.h if you do want to put this in a header file.
But my preference would be to put this in the CMakeLists.txt itself, which I think makes it a bit more discoverable. (And there's some prior art there - the similar functionality of DEBUG_POOL and MSVC_CRTDBG just fiddles compiler flags.)
I would just put:
ADD_DEFINITIONS(-D GIT_ASAN)
in the IF (ASAN) block.
c01b676 to
5bea6e8
Compare
|
Rebased (ping @lhchavez). Caveats/notes :
(Speaking about pkgconfig generation, I've written a module to do this for the mbedTLS project) |
lhchavez
left a comment
There was a problem hiding this comment.
works for me! thanks for making this change :D
|
Rebased, I've added the |
lhchavez
left a comment
There was a problem hiding this comment.
I'd advocate for enabling a subset of the sanitizers when fuzzing since that catches a lot more bugs. But we (most likely I) can enable that later if you don't want to do it now.
I wrote some docs for how to use fuzzing: https://github.com/libgit2/libgit2/blob/master/docs/fuzzing.md
The CI build adds the USE_STANDALONE_FUZZER, which only lets you run the pre-canned corpus to avoid taking too much time.
OSS Fuzz builds things a bit differently, though: https://github.com/google/oss-fuzz/blob/master/projects/libgit2/build.sh
I'll happily defer that to you, then 😉. Feel free to push those tweaks there or ping me to cherrypick something, in case merging takes longer. |
|
The OSS project already enables sanitizers by itself, so there's nothing we need to change there. And I don't think it makes a lot of sense for our standalone fuzzers: they're mainly intended as a way to verify that our fuzzers build, all the real work is deferred to OSS Fuzz. |
|
I'm going through some older PRs — I think that this is quite outdated, apologies. We have a lot of fuzzing in |
Extracted from #3883, with CMake support thanks to arsenm/sanitizers-cmake.
Add
-DASAN=ON -DBUILD_CLAR=ONto your favorite CMake invocation.Notes:
libgit2_clar, so the main library isn't instrumented.address,thread,memoryandundefined). Apple's clang only supportsaddressatm, so I'm interested to see what happens on the Linux build 😉