diff options
author | Matthew Dempsky <mdempsky@google.com> | 2019-10-28 15:30:35 -0700 |
---|---|---|
committer | Matthew Dempsky <mdempsky@google.com> | 2019-11-05 00:00:43 +0000 |
commit | ea0b4e7c7db8c5d376e77fd3e6741d94685073ac (patch) | |
tree | 8afdc5178caea495179b453a704b6207d3dc1ad0 /src/runtime/libfuzzer_amd64.s | |
parent | e341e93c519ef22ed4759fd0b4643a30321b9222 (diff) | |
download | go-ea0b4e7c7db8c5d376e77fd3e6741d94685073ac.tar.gz go-ea0b4e7c7db8c5d376e77fd3e6741d94685073ac.zip |
cmd/compile, runtime: add comparison tracing for libFuzzer
This CL extends cmd/compile's experimental libFuzzer support with
calls to __sanitizer_cov_trace_{,const_}cmp{1,2,4,8}. This allows much
more efficient fuzzing of comparisons.
Only supports amd64 and arm64 for now.
Updates #14565.
Change-Id: Ibf82a8d9658f2bc50d955bdb1ae26723a3f0584d
Reviewed-on: https://go-review.googlesource.com/c/go/+/203887
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/runtime/libfuzzer_amd64.s')
-rw-r--r-- | src/runtime/libfuzzer_amd64.s | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/runtime/libfuzzer_amd64.s b/src/runtime/libfuzzer_amd64.s new file mode 100644 index 0000000000..890fde341b --- /dev/null +++ b/src/runtime/libfuzzer_amd64.s @@ -0,0 +1,42 @@ +// Copyright 2019 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build libfuzzer + +#include "go_asm.h" +#include "go_tls.h" +#include "textflag.h" + +// Based on race_amd64.s; see commentary there. + +#ifdef GOOS_windows +#define RARG0 CX +#define RARG1 DX +#else +#define RARG0 DI +#define RARG1 SI +#endif + +// void runtime·libfuzzerCall(fn, arg0, arg1 uintptr) +// Calls C function fn from libFuzzer and passes 2 arguments to it. +TEXT runtime·libfuzzerCall(SB), NOSPLIT, $0-24 + MOVQ fn+0(FP), AX + MOVQ arg0+8(FP), RARG0 + MOVQ arg1+16(FP), RARG1 + + get_tls(R12) + MOVQ g(R12), R14 + MOVQ g_m(R14), R13 + + // Switch to g0 stack. + MOVQ SP, R12 // callee-saved, preserved across the CALL + MOVQ m_g0(R13), R10 + CMPQ R10, R14 + JE call // already on g0 + MOVQ (g_sched+gobuf_sp)(R10), SP +call: + ANDQ $~15, SP // alignment for gcc ABI + CALL AX + MOVQ R12, SP + RET |