Merge "Updated the way we build AFL++ fuzz binaries"

This commit is contained in:
Cory Barker
2022-08-08 14:24:16 +00:00
committed by Gerrit Code Review
5 changed files with 128 additions and 130 deletions

View File

@@ -27,13 +27,21 @@ import (
"android/soong/android"
)
type FuzzType string
type Lang string
const (
Cc FuzzType = ""
Rust FuzzType = "rust"
Java FuzzType = "java"
AFL FuzzType = "AFL"
Cc Lang = "cc"
Rust Lang = "rust"
Java Lang = "java"
)
type Framework string
const (
AFL Framework = "afl"
LibFuzzer Framework = "libfuzzer"
Jazzer Framework = "jazzer"
UnknownFramework Framework = "unknownframework"
)
var BoolDefault = proptools.BoolDefault
@@ -48,7 +56,6 @@ type FuzzPackager struct {
Packages android.Paths
FuzzTargets map[string]bool
SharedLibInstallStrings []string
FuzzType FuzzType
}
type FileToZip struct {
@@ -146,6 +153,12 @@ type FuzzConfig struct {
IsJni *bool `json:"is_jni,omitempty"`
}
type FuzzFrameworks struct {
Afl *bool
Libfuzzer *bool
Jazzer *bool
}
type FuzzProperties struct {
// Optional list of seed files to be installed to the fuzz target's output
// directory.
@@ -155,6 +168,10 @@ type FuzzProperties struct {
Data []string `android:"path"`
// Optional dictionary to be installed to the fuzz target's output directory.
Dictionary *string `android:"path"`
// Define the fuzzing frameworks this fuzz target can be built for. If
// empty then the fuzz target will be available to be built for all fuzz
// frameworks available
Fuzzing_frameworks *FuzzFrameworks
// Config for running the target on fuzzing infrastructure.
Fuzz_config *FuzzConfig
}
@@ -169,6 +186,49 @@ type FuzzPackagedModule struct {
DataIntermediateDir android.Path
}
func GetFramework(ctx android.LoadHookContext, lang Lang) Framework {
framework := ctx.Config().Getenv("FUZZ_FRAMEWORK")
if lang == Cc {
switch strings.ToLower(framework) {
case "":
return LibFuzzer
case "libfuzzer":
return LibFuzzer
case "afl":
return AFL
}
} else if lang == Rust {
return LibFuzzer
} else if lang == Java {
return Jazzer
}
ctx.ModuleErrorf(fmt.Sprintf("%s is not a valid fuzzing framework for %s", framework, lang))
return UnknownFramework
}
func IsValidFrameworkForModule(targetFramework Framework, lang Lang, moduleFrameworks *FuzzFrameworks) bool {
if targetFramework == UnknownFramework {
return false
}
if moduleFrameworks == nil {
return true
}
switch targetFramework {
case LibFuzzer:
return proptools.BoolDefault(moduleFrameworks.Libfuzzer, true)
case AFL:
return proptools.BoolDefault(moduleFrameworks.Afl, true)
case Jazzer:
return proptools.BoolDefault(moduleFrameworks.Jazzer, true)
default:
panic("%s is not supported as a fuzz framework")
}
}
func IsValid(fuzzModule FuzzModule) bool {
// Discard ramdisk + vendor_ramdisk + recovery modules, they're duplicates of
// fuzz targets we're going to package anyway.
@@ -267,7 +327,7 @@ func (f *FuzzConfig) String() string {
return string(b)
}
func (s *FuzzPackager) CreateFuzzPackage(ctx android.SingletonContext, archDirs map[ArchOs][]FileToZip, fuzzType FuzzType, pctx android.PackageContext) {
func (s *FuzzPackager) CreateFuzzPackage(ctx android.SingletonContext, archDirs map[ArchOs][]FileToZip, fuzzType Lang, pctx android.PackageContext) {
var archOsList []ArchOs
for archOs := range archDirs {
archOsList = append(archOsList, archOs)
@@ -286,9 +346,7 @@ func (s *FuzzPackager) CreateFuzzPackage(ctx android.SingletonContext, archDirs
if fuzzType == Java {
zipFileName = "fuzz-java-" + hostOrTarget + "-" + arch + ".zip"
}
if fuzzType == AFL {
zipFileName = "fuzz-afl-" + hostOrTarget + "-" + arch + ".zip"
}
outputFile := android.PathForOutput(ctx, zipFileName)
s.Packages = append(s.Packages, outputFile)