Moving common fuzzing code to fuzz package
Test: make haiku and make haiku-rust Change-Id: Ife80cc10672f51bd6afbae7061cc9373a2a15e7d
This commit is contained in:
parent
60880e0517
commit
c0a671fc80
7 changed files with 94 additions and 71 deletions
|
@ -13,6 +13,7 @@ bootstrap_go_package {
|
|||
"soong-bazel",
|
||||
"soong-cc-config",
|
||||
"soong-etc",
|
||||
"soong-fuzz",
|
||||
"soong-genrule",
|
||||
"soong-snapshot",
|
||||
"soong-tradefed",
|
||||
|
@ -59,7 +60,6 @@ bootstrap_go_package {
|
|||
"binary.go",
|
||||
"binary_sdk_member.go",
|
||||
"fuzz.go",
|
||||
"fuzz_common.go",
|
||||
"library.go",
|
||||
"library_headers.go",
|
||||
"library_sdk_member.go",
|
||||
|
|
5
cc/cc.go
5
cc/cc.go
|
@ -29,6 +29,7 @@ import (
|
|||
|
||||
"android/soong/android"
|
||||
"android/soong/cc/config"
|
||||
"android/soong/fuzz"
|
||||
"android/soong/genrule"
|
||||
)
|
||||
|
||||
|
@ -762,7 +763,7 @@ func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
|
|||
// members of the cc.Module to this decorator. Thus, a cc_binary module has custom linker and
|
||||
// installer logic.
|
||||
type Module struct {
|
||||
FuzzModule
|
||||
fuzz.FuzzModule
|
||||
|
||||
android.SdkBase
|
||||
android.BazelModuleBase
|
||||
|
@ -3415,7 +3416,7 @@ func DefaultsFactory(props ...interface{}) android.Module {
|
|||
&TestProperties{},
|
||||
&TestBinaryProperties{},
|
||||
&BenchmarkProperties{},
|
||||
&FuzzProperties{},
|
||||
&fuzz.FuzzProperties{},
|
||||
&StlProperties{},
|
||||
&SanitizeProperties{},
|
||||
&StripProperties{},
|
||||
|
|
67
cc/fuzz.go
67
cc/fuzz.go
|
@ -15,7 +15,6 @@
|
|||
package cc
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
|
@ -24,55 +23,9 @@ import (
|
|||
|
||||
"android/soong/android"
|
||||
"android/soong/cc/config"
|
||||
"android/soong/fuzz"
|
||||
)
|
||||
|
||||
type FuzzConfig struct {
|
||||
// Email address of people to CC on bugs or contact about this fuzz target.
|
||||
Cc []string `json:"cc,omitempty"`
|
||||
// Specify whether to enable continuous fuzzing on devices. Defaults to true.
|
||||
Fuzz_on_haiku_device *bool `json:"fuzz_on_haiku_device,omitempty"`
|
||||
// Specify whether to enable continuous fuzzing on host. Defaults to true.
|
||||
Fuzz_on_haiku_host *bool `json:"fuzz_on_haiku_host,omitempty"`
|
||||
// Component in Google's bug tracking system that bugs should be filed to.
|
||||
Componentid *int64 `json:"componentid,omitempty"`
|
||||
// Hotlists in Google's bug tracking system that bugs should be marked with.
|
||||
Hotlists []string `json:"hotlists,omitempty"`
|
||||
// Specify whether this fuzz target was submitted by a researcher. Defaults
|
||||
// to false.
|
||||
Researcher_submitted *bool `json:"researcher_submitted,omitempty"`
|
||||
// Specify who should be acknowledged for CVEs in the Android Security
|
||||
// Bulletin.
|
||||
Acknowledgement []string `json:"acknowledgement,omitempty"`
|
||||
// Additional options to be passed to libfuzzer when run in Haiku.
|
||||
Libfuzzer_options []string `json:"libfuzzer_options,omitempty"`
|
||||
// Additional options to be passed to HWASAN when running on-device in Haiku.
|
||||
Hwasan_options []string `json:"hwasan_options,omitempty"`
|
||||
// Additional options to be passed to HWASAN when running on host in Haiku.
|
||||
Asan_options []string `json:"asan_options,omitempty"`
|
||||
}
|
||||
|
||||
func (f *FuzzConfig) String() string {
|
||||
b, err := json.Marshal(f)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return string(b)
|
||||
}
|
||||
|
||||
type FuzzProperties struct {
|
||||
// Optional list of seed files to be installed to the fuzz target's output
|
||||
// directory.
|
||||
Corpus []string `android:"path"`
|
||||
// Optional list of data files to be installed to the fuzz target's output
|
||||
// directory. Directory structure relative to the module is preserved.
|
||||
Data []string `android:"path"`
|
||||
// Optional dictionary to be installed to the fuzz target's output directory.
|
||||
Dictionary *string `android:"path"`
|
||||
// Config for running the target on fuzzing infrastructure.
|
||||
Fuzz_config *FuzzConfig
|
||||
}
|
||||
|
||||
func init() {
|
||||
android.RegisterModuleType("cc_fuzz", FuzzFactory)
|
||||
android.RegisterSingletonType("cc_fuzz_packaging", fuzzPackagingFactory)
|
||||
|
@ -94,7 +47,7 @@ type fuzzBinary struct {
|
|||
*binaryDecorator
|
||||
*baseCompiler
|
||||
|
||||
fuzzPackagedModule FuzzPackagedModule
|
||||
fuzzPackagedModule fuzz.FuzzPackagedModule
|
||||
|
||||
installedSharedDeps []string
|
||||
}
|
||||
|
@ -355,7 +308,7 @@ func NewFuzz(hod android.HostOrDeviceSupported) *Module {
|
|||
// Responsible for generating GNU Make rules that package fuzz targets into
|
||||
// their architecture & target/host specific zip file.
|
||||
type ccFuzzPackager struct {
|
||||
FuzzPackager
|
||||
fuzz.FuzzPackager
|
||||
sharedLibInstallStrings []string
|
||||
}
|
||||
|
||||
|
@ -367,7 +320,7 @@ func (s *ccFuzzPackager) GenerateBuildActions(ctx android.SingletonContext) {
|
|||
// Map between each architecture + host/device combination, and the files that
|
||||
// need to be packaged (in the tuple of {source file, destination folder in
|
||||
// archive}).
|
||||
archDirs := make(map[ArchOs][]FileToZip)
|
||||
archDirs := make(map[fuzz.ArchOs][]fuzz.FileToZip)
|
||||
|
||||
// Map tracking whether each shared library has an install rule to avoid duplicate install rules from
|
||||
// multiple fuzzers that depend on the same shared library.
|
||||
|
@ -384,7 +337,7 @@ func (s *ccFuzzPackager) GenerateBuildActions(ctx android.SingletonContext) {
|
|||
}
|
||||
|
||||
// Discard non-fuzz targets.
|
||||
if ok := IsValid(ccModule.FuzzModule); !ok {
|
||||
if ok := fuzz.IsValid(ccModule.FuzzModule); !ok {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -400,12 +353,12 @@ func (s *ccFuzzPackager) GenerateBuildActions(ctx android.SingletonContext) {
|
|||
|
||||
archString := ccModule.Arch().ArchType.String()
|
||||
archDir := android.PathForIntermediates(ctx, "fuzz", hostOrTargetString, archString)
|
||||
archOs := ArchOs{HostOrTarget: hostOrTargetString, Arch: archString, Dir: archDir.String()}
|
||||
archOs := fuzz.ArchOs{HostOrTarget: hostOrTargetString, Arch: archString, Dir: archDir.String()}
|
||||
|
||||
// Grab the list of required shared libraries.
|
||||
sharedLibraries := collectAllSharedDependencies(ctx, module)
|
||||
|
||||
var files []FileToZip
|
||||
var files []fuzz.FileToZip
|
||||
builder := android.NewRuleBuilder(pctx, ctx)
|
||||
|
||||
// Package the corpus, data, dict and config into a zipfile.
|
||||
|
@ -414,7 +367,7 @@ func (s *ccFuzzPackager) GenerateBuildActions(ctx android.SingletonContext) {
|
|||
// Find and mark all the transiently-dependent shared libraries for
|
||||
// packaging.
|
||||
for _, library := range sharedLibraries {
|
||||
files = append(files, FileToZip{library, "lib"})
|
||||
files = append(files, fuzz.FileToZip{library, "lib"})
|
||||
|
||||
// For each architecture-specific shared library dependency, we need to
|
||||
// install it to the output directory. Setup the install destination here,
|
||||
|
@ -446,7 +399,7 @@ func (s *ccFuzzPackager) GenerateBuildActions(ctx android.SingletonContext) {
|
|||
}
|
||||
|
||||
// The executable.
|
||||
files = append(files, FileToZip{ccModule.UnstrippedOutputFile(), ""})
|
||||
files = append(files, fuzz.FileToZip{ccModule.UnstrippedOutputFile(), ""})
|
||||
|
||||
archDirs[archOs], ok = s.BuildZipFile(ctx, module, fuzzModule.fuzzPackagedModule, files, builder, archDir, archString, hostOrTargetString, archOs, archDirs)
|
||||
if !ok {
|
||||
|
@ -454,7 +407,7 @@ func (s *ccFuzzPackager) GenerateBuildActions(ctx android.SingletonContext) {
|
|||
}
|
||||
})
|
||||
|
||||
s.CreateFuzzPackage(ctx, archDirs, Cc)
|
||||
s.CreateFuzzPackage(ctx, archDirs, fuzz.Cc, pctx)
|
||||
|
||||
}
|
||||
|
||||
|
|
15
fuzz/Android.bp
Normal file
15
fuzz/Android.bp
Normal file
|
@ -0,0 +1,15 @@
|
|||
package {
|
||||
default_applicable_licenses: ["Android-Apache-2.0"],
|
||||
}
|
||||
|
||||
bootstrap_go_package {
|
||||
name: "soong-fuzz",
|
||||
pkgPath: "android/soong/fuzz",
|
||||
deps: [
|
||||
"soong-android",
|
||||
],
|
||||
srcs: [
|
||||
"fuzz_common.go",
|
||||
],
|
||||
pluginFor: ["soong_build"],
|
||||
}
|
|
@ -12,14 +12,17 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package cc
|
||||
package fuzz
|
||||
|
||||
// This file contains the common code for compiling C/C++ and Rust fuzzers for Android.
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/google/blueprint/proptools"
|
||||
|
||||
"android/soong/android"
|
||||
)
|
||||
|
||||
|
@ -30,6 +33,8 @@ const (
|
|||
Rust Lang = "rust"
|
||||
)
|
||||
|
||||
var BoolDefault = proptools.BoolDefault
|
||||
|
||||
type FuzzModule struct {
|
||||
android.ModuleBase
|
||||
android.DefaultableModuleBase
|
||||
|
@ -52,6 +57,44 @@ type ArchOs struct {
|
|||
Dir string
|
||||
}
|
||||
|
||||
type FuzzConfig struct {
|
||||
// Email address of people to CC on bugs or contact about this fuzz target.
|
||||
Cc []string `json:"cc,omitempty"`
|
||||
// Specify whether to enable continuous fuzzing on devices. Defaults to true.
|
||||
Fuzz_on_haiku_device *bool `json:"fuzz_on_haiku_device,omitempty"`
|
||||
// Specify whether to enable continuous fuzzing on host. Defaults to true.
|
||||
Fuzz_on_haiku_host *bool `json:"fuzz_on_haiku_host,omitempty"`
|
||||
// Component in Google's bug tracking system that bugs should be filed to.
|
||||
Componentid *int64 `json:"componentid,omitempty"`
|
||||
// Hotlists in Google's bug tracking system that bugs should be marked with.
|
||||
Hotlists []string `json:"hotlists,omitempty"`
|
||||
// Specify whether this fuzz target was submitted by a researcher. Defaults
|
||||
// to false.
|
||||
Researcher_submitted *bool `json:"researcher_submitted,omitempty"`
|
||||
// Specify who should be acknowledged for CVEs in the Android Security
|
||||
// Bulletin.
|
||||
Acknowledgement []string `json:"acknowledgement,omitempty"`
|
||||
// Additional options to be passed to libfuzzer when run in Haiku.
|
||||
Libfuzzer_options []string `json:"libfuzzer_options,omitempty"`
|
||||
// Additional options to be passed to HWASAN when running on-device in Haiku.
|
||||
Hwasan_options []string `json:"hwasan_options,omitempty"`
|
||||
// Additional options to be passed to HWASAN when running on host in Haiku.
|
||||
Asan_options []string `json:"asan_options,omitempty"`
|
||||
}
|
||||
|
||||
type FuzzProperties struct {
|
||||
// Optional list of seed files to be installed to the fuzz target's output
|
||||
// directory.
|
||||
Corpus []string `android:"path"`
|
||||
// Optional list of data files to be installed to the fuzz target's output
|
||||
// directory. Directory structure relative to the module is preserved.
|
||||
Data []string `android:"path"`
|
||||
// Optional dictionary to be installed to the fuzz target's output directory.
|
||||
Dictionary *string `android:"path"`
|
||||
// Config for running the target on fuzzing infrastructure.
|
||||
Fuzz_config *FuzzConfig
|
||||
}
|
||||
|
||||
type FuzzPackagedModule struct {
|
||||
FuzzProperties FuzzProperties
|
||||
Dictionary android.Path
|
||||
|
@ -151,7 +194,16 @@ func (s *FuzzPackager) BuildZipFile(ctx android.SingletonContext, module android
|
|||
return archDirs[archOs], true
|
||||
}
|
||||
|
||||
func (s *FuzzPackager) CreateFuzzPackage(ctx android.SingletonContext, archDirs map[ArchOs][]FileToZip, lang Lang) {
|
||||
func (f *FuzzConfig) String() string {
|
||||
b, err := json.Marshal(f)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func (s *FuzzPackager) CreateFuzzPackage(ctx android.SingletonContext, archDirs map[ArchOs][]FileToZip, lang Lang, pctx android.PackageContext) {
|
||||
var archOsList []ArchOs
|
||||
for archOs := range archDirs {
|
||||
archOsList = append(archOsList, archOs)
|
17
rust/fuzz.go
17
rust/fuzz.go
|
@ -21,6 +21,7 @@ import (
|
|||
|
||||
"android/soong/android"
|
||||
"android/soong/cc"
|
||||
"android/soong/fuzz"
|
||||
"android/soong/rust/config"
|
||||
)
|
||||
|
||||
|
@ -32,7 +33,7 @@ func init() {
|
|||
type fuzzDecorator struct {
|
||||
*binaryDecorator
|
||||
|
||||
fuzzPackagedModule cc.FuzzPackagedModule
|
||||
fuzzPackagedModule fuzz.FuzzPackagedModule
|
||||
}
|
||||
|
||||
var _ compiler = (*binaryDecorator)(nil)
|
||||
|
@ -96,7 +97,7 @@ func (fuzzer *fuzzDecorator) autoDep(ctx android.BottomUpMutatorContext) autoDep
|
|||
// Responsible for generating GNU Make rules that package fuzz targets into
|
||||
// their architecture & target/host specific zip file.
|
||||
type rustFuzzPackager struct {
|
||||
cc.FuzzPackager
|
||||
fuzz.FuzzPackager
|
||||
}
|
||||
|
||||
func rustFuzzPackagingFactory() android.Singleton {
|
||||
|
@ -105,7 +106,7 @@ func rustFuzzPackagingFactory() android.Singleton {
|
|||
|
||||
func (s *rustFuzzPackager) GenerateBuildActions(ctx android.SingletonContext) {
|
||||
// Map between each architecture + host/device combination.
|
||||
archDirs := make(map[cc.ArchOs][]cc.FileToZip)
|
||||
archDirs := make(map[fuzz.ArchOs][]fuzz.FileToZip)
|
||||
|
||||
// List of individual fuzz targets.
|
||||
s.FuzzTargets = make(map[string]bool)
|
||||
|
@ -117,7 +118,7 @@ func (s *rustFuzzPackager) GenerateBuildActions(ctx android.SingletonContext) {
|
|||
return
|
||||
}
|
||||
|
||||
if ok := cc.IsValid(rustModule.FuzzModule); !ok || rustModule.Properties.PreventInstall {
|
||||
if ok := fuzz.IsValid(rustModule.FuzzModule); !ok || rustModule.Properties.PreventInstall {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -133,16 +134,16 @@ func (s *rustFuzzPackager) GenerateBuildActions(ctx android.SingletonContext) {
|
|||
|
||||
archString := rustModule.Arch().ArchType.String()
|
||||
archDir := android.PathForIntermediates(ctx, "fuzz", hostOrTargetString, archString)
|
||||
archOs := cc.ArchOs{HostOrTarget: hostOrTargetString, Arch: archString, Dir: archDir.String()}
|
||||
archOs := fuzz.ArchOs{HostOrTarget: hostOrTargetString, Arch: archString, Dir: archDir.String()}
|
||||
|
||||
var files []cc.FileToZip
|
||||
var files []fuzz.FileToZip
|
||||
builder := android.NewRuleBuilder(pctx, ctx)
|
||||
|
||||
// Package the artifacts (data, corpus, config and dictionary into a zipfile.
|
||||
files = s.PackageArtifacts(ctx, module, fuzzModule.fuzzPackagedModule, archDir, builder)
|
||||
|
||||
// The executable.
|
||||
files = append(files, cc.FileToZip{rustModule.unstrippedOutputFile.Path(), ""})
|
||||
files = append(files, fuzz.FileToZip{rustModule.unstrippedOutputFile.Path(), ""})
|
||||
|
||||
archDirs[archOs], ok = s.BuildZipFile(ctx, module, fuzzModule.fuzzPackagedModule, files, builder, archDir, archString, hostOrTargetString, archOs, archDirs)
|
||||
if !ok {
|
||||
|
@ -150,7 +151,7 @@ func (s *rustFuzzPackager) GenerateBuildActions(ctx android.SingletonContext) {
|
|||
}
|
||||
|
||||
})
|
||||
s.CreateFuzzPackage(ctx, archDirs, cc.Rust)
|
||||
s.CreateFuzzPackage(ctx, archDirs, fuzz.Rust, pctx)
|
||||
}
|
||||
|
||||
func (s *rustFuzzPackager) MakeVars(ctx android.MakeVarsContext) {
|
||||
|
|
|
@ -25,6 +25,7 @@ import (
|
|||
"android/soong/bloaty"
|
||||
"android/soong/cc"
|
||||
cc_config "android/soong/cc/config"
|
||||
"android/soong/fuzz"
|
||||
"android/soong/rust/config"
|
||||
)
|
||||
|
||||
|
@ -123,7 +124,7 @@ type BaseProperties struct {
|
|||
}
|
||||
|
||||
type Module struct {
|
||||
cc.FuzzModule
|
||||
fuzz.FuzzModule
|
||||
|
||||
VendorProperties cc.VendorProperties
|
||||
|
||||
|
|
Loading…
Reference in a new issue