forked from bazel-contrib/rules_go
-
Notifications
You must be signed in to change notification settings - Fork 5
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
Currently, there isn't a reliable way to build #20
Draft
srosenberg
wants to merge
1
commit into
release-0.46
Choose a base branch
from
sr/support_libfuzzer_instrumentation
base: release-0.46
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ import ( | |
"os/exec" | ||
"path" | ||
"path/filepath" | ||
"slices" | ||
"sort" | ||
"strings" | ||
) | ||
|
@@ -343,6 +344,17 @@ func compileArchive( | |
cgoSrcs[i-len(goSrcs)] = coverSrc | ||
} | ||
} | ||
if strings.Contains(outLinkObj, "external/") && slices.Contains(gcFlags, "-d=libfuzzer") { | ||
// Remove -d=libfuzzer from gcFlags when compiling external packages. We don't really want to instrument them, | ||
// and they may not link without libfuzzer_shim.go. | ||
gcFlags = slices.DeleteFunc(gcFlags, func(s string) bool { | ||
return s == "-d=libfuzzer" | ||
}) | ||
} | ||
// Log instrumented objs for ease of tracking/debugging. | ||
if slices.Contains(gcFlags, "-d=libfuzzer") { | ||
fmt.Printf("%s -- gcFlags=%s\n", outLinkObj, gcFlags) | ||
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 don't think we want this checked in. 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. Yep, I'll remove; couldn't find a standard way of logging debug messages, which would get suppressed by default. |
||
} | ||
|
||
// If we have cgo, generate separate C and go files, and compile the | ||
// C files. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2021 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. | ||
|
||
// N.B. This source is lifted verbatim from trace.go, added in | ||
// https://github.com/golang/go/commit/74f49f3366826f95a464cc15838a0668c92e3357 | ||
// | ||
// It's essentially a shim to allow linking a Go test binary without libfuzzer. | ||
// We chose the 'bzltestutil' package because it's a bazel dependency for all Go test binaries. | ||
|
||
//go:build !libfuzzer | ||
|
||
package bzltestutil | ||
|
||
import _ "unsafe" // for go:linkname | ||
|
||
//go:linkname libfuzzerTraceCmp1 runtime.libfuzzerTraceCmp1 | ||
//go:linkname libfuzzerTraceCmp2 runtime.libfuzzerTraceCmp2 | ||
//go:linkname libfuzzerTraceCmp4 runtime.libfuzzerTraceCmp4 | ||
//go:linkname libfuzzerTraceCmp8 runtime.libfuzzerTraceCmp8 | ||
|
||
//go:linkname libfuzzerTraceConstCmp1 runtime.libfuzzerTraceConstCmp1 | ||
//go:linkname libfuzzerTraceConstCmp2 runtime.libfuzzerTraceConstCmp2 | ||
//go:linkname libfuzzerTraceConstCmp4 runtime.libfuzzerTraceConstCmp4 | ||
//go:linkname libfuzzerTraceConstCmp8 runtime.libfuzzerTraceConstCmp8 | ||
|
||
//go:linkname libfuzzerHookStrCmp runtime.libfuzzerHookStrCmp | ||
//go:linkname libfuzzerHookEqualFold runtime.libfuzzerHookEqualFold | ||
|
||
func libfuzzerTraceCmp1(arg0, arg1 uint8, fakePC int) {} | ||
func libfuzzerTraceCmp2(arg0, arg1 uint16, fakePC int) {} | ||
func libfuzzerTraceCmp4(arg0, arg1 uint32, fakePC int) {} | ||
func libfuzzerTraceCmp8(arg0, arg1 uint64, fakePC int) {} | ||
|
||
func libfuzzerTraceConstCmp1(arg0, arg1 uint8, fakePC int) {} | ||
func libfuzzerTraceConstCmp2(arg0, arg1 uint16, fakePC int) {} | ||
func libfuzzerTraceConstCmp4(arg0, arg1 uint32, fakePC int) {} | ||
func libfuzzerTraceConstCmp8(arg0, arg1 uint64, fakePC int) {} | ||
|
||
func libfuzzerHookStrCmp(arg0, arg1 string, fakePC int) {} | ||
func libfuzzerHookEqualFold(arg0, arg1 string, fakePC int) {} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rickystewart I couldn't find a cleaner way to determine whether we're compiling an external dependency, but this seems to work. Maybe you have a better idea?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably how I would do it.