[llvm] r270145 - [LibFuzzer]

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Thu May 19 16:53:59 PDT 2016


On Thu, May 19, 2016 at 3:00 PM, Dan Liew via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> Author: delcypher
> Date: Thu May 19 17:00:33 2016
> New Revision: 270145
>
> URL: http://llvm.org/viewvc/llvm-project?rev=270145&view=rev
> Log:
> [LibFuzzer]
> Work around crashes in ``__sanitizer_malloc_hook()`` under Mac OSX.
>

It works best if the first line of your commit message provides a summary
of the change - as this line becomes the subject of the email (& is used in
version control summary logs, etc). In this case the subject was only
"[LibFuzzer]" (personally - I err on the side of violating the 80 column or
whatever limit my editor imposes on the commit message if it means making
that first line more fully descriptive)


>
> Under Mac OSX we intercept calls to malloc before thread local
> storage is initialised leading to a crash when accessing
> ``AllocTracer``. To workaround this ``AllocTracer`` is only accessed
> in the hook under Linux. For symmetry ``__sanitizer_free_hook()``
> is also modified in the same way.
>
> To support this change a set of new macros
> LIBFUZZER_LINUX and LIBFUZZER_APPLE has been defined which can be
> used to check the target being compiled for.
>
> Differential Revision: http://reviews.llvm.org/D20402
>
> Modified:
>     llvm/trunk/lib/Fuzzer/FuzzerInternal.h
>     llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp
>
> Modified: llvm/trunk/lib/Fuzzer/FuzzerInternal.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerInternal.h?rev=270145&r1=270144&r2=270145&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Fuzzer/FuzzerInternal.h (original)
> +++ llvm/trunk/lib/Fuzzer/FuzzerInternal.h Thu May 19 17:00:33 2016
> @@ -27,6 +27,17 @@
>  #include "FuzzerInterface.h"
>  #include "FuzzerTracePC.h"
>
> +// Platform detection.
> +#ifdef __linux__
> +#define LIBFUZZER_LINUX 1
> +#define LIBFUZZER_APPLE 0
> +#elif __APPLE__
> +#define LIBFUZZER_LINUX 0
> +#define LIBFUZZER_APPLE 1
> +#else
> +#error "Support for your platform has not been implemented"
> +#endif
> +
>  namespace fuzzer {
>
>  typedef int (*UserCallback)(const uint8_t *Data, size_t Size);
>
> Modified: llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp?rev=270145&r1=270144&r2=270145&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp (original)
> +++ llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp Thu May 19 17:00:33 2016
> @@ -437,9 +437,19 @@ struct MallocFreeTracer {
>
>  static thread_local MallocFreeTracer AllocTracer;
>
> +// FIXME: The hooks only count on Linux because
> +// on Mac OSX calls to malloc are intercepted before
> +// thread local storage is initialised leading to
> +// crashes when accessing ``AllocTracer``.
>  extern "C" {
> -void __sanitizer_malloc_hook(void *ptr, size_t size) {
> AllocTracer.Mallocs++; }
> -void __sanitizer_free_hook(void *ptr) { AllocTracer.Frees++; }
> +void __sanitizer_malloc_hook(void *ptr, size_t size) {
> +  if (!LIBFUZZER_APPLE)
> +    AllocTracer.Mallocs++;
> +}
> +void __sanitizer_free_hook(void *ptr) {
> +  if (!LIBFUZZER_APPLE)
> +    AllocTracer.Frees++;
> +}
>  }  // extern "C"
>
>  void Fuzzer::ExecuteCallback(const uint8_t *Data, size_t Size) {
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160519/11707548/attachment.html>


More information about the llvm-commits mailing list