-
Notifications
You must be signed in to change notification settings - Fork 0
Dev.libfuzzer #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,16 +5,35 @@ | |
package walk | ||
|
||
import ( | ||
"go/constant" | ||
|
||
"cmd/compile/internal/base" | ||
"cmd/compile/internal/ir" | ||
"cmd/compile/internal/reflectdata" | ||
"cmd/compile/internal/ssagen" | ||
"cmd/compile/internal/typecheck" | ||
"cmd/compile/internal/types" | ||
"encoding/binary" | ||
"fmt" | ||
"go/constant" | ||
"hash/fnv" | ||
"io" | ||
) | ||
|
||
func fakePC(n ir.Node) ir.Node { | ||
// In order to get deterministic IDs, we include the package path, file index, line number, column number | ||
// in the calculation of the fakePC for the IR node. | ||
hash := fnv.New32() | ||
// We ignore the errors here because the `io.Writer` in the `hash.Hash` interface never returns an error. | ||
_, _ = io.WriteString(hash, base.Ctxt.Pkgpath) | ||
_ = binary.Write(hash, binary.LittleEndian, n.Pos().FileIndex()) | ||
_ = binary.Write(hash, binary.LittleEndian, int64(n.Pos().Line())) | ||
_ = binary.Write(hash, binary.LittleEndian, int64(n.Pos().Col())) | ||
// We also include the string representation of the node to distinguish autogenerated expression since | ||
// those get the same `src.XPos` | ||
_, _ = io.WriteString(hash, fmt.Sprintf("%v", n)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These nodes seem to have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some nodes such as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, it's probably better than the alternatives then. Do we still have to hash in the other fields or are they also part of the string representation? |
||
|
||
return ir.NewInt(int64(hash.Sum32())) | ||
} | ||
|
||
// The result of walkCompare MUST be assigned back to n, e.g. | ||
// n.Left = walkCompare(n.Left, init) | ||
func walkCompare(n *ir.BinaryExpr, init *ir.Nodes) ir.Node { | ||
|
@@ -131,7 +150,8 @@ func walkCompare(n *ir.BinaryExpr, init *ir.Nodes) ir.Node { | |
default: | ||
base.Fatalf("unexpected integer size %d for %v", t.Size(), t) | ||
} | ||
init.Append(mkcall(fn, nil, init, tracecmpArg(l, paramType, init), tracecmpArg(r, paramType, init))) | ||
|
||
init.Append(mkcall(fn, nil, init, tracecmpArg(l, paramType, init), tracecmpArg(r, paramType, init), fakePC(n))) | ||
} | ||
return n | ||
case types.TARRAY: | ||
|
@@ -399,8 +419,16 @@ func walkCompareString(n *ir.BinaryExpr, init *ir.Nodes) ir.Node { | |
r = mkcall("cmpstring", types.Types[types.TINT], init, typecheck.Conv(n.X, types.Types[types.TSTRING]), typecheck.Conv(n.Y, types.Types[types.TSTRING])) | ||
r = ir.NewBinaryExpr(base.Pos, n.Op(), r, ir.NewInt(0)) | ||
} | ||
|
||
return finishCompare(n, r, init) | ||
result := finishCompare(n, r, init) | ||
if base.Debug.Libfuzzer != 0 { | ||
fn := "libfuzzerHookStrCmp" | ||
x := cheapExpr(n.X, init) | ||
y := cheapExpr(n.Y, init) | ||
z := cheapExpr(result, init) | ||
paramType := types.Types[types.TSTRING] | ||
init.Append(mkcall(fn, nil, init, tracecmpArg(x, paramType, init), tracecmpArg(y, paramType, init), tracecmpArg(z, n.Type(), init), fakePC(n))) | ||
} | ||
return result | ||
} | ||
|
||
// The result of finishCompare MUST be assigned back to n, e.g. | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.