aboutsummaryrefslogtreecommitdiffstats
path: root/sys/syz-extract/fetch.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2017-09-13 16:13:38 +0200
committerDmitry Vyukov <dvyukov@google.com>2017-09-15 16:02:37 +0200
commitb16ba6390d6b2731bf5cfa0ef04aa1299b7306cf (patch)
tree85befaf31dffaf414b12241ff53f5c08a9dc4187 /sys/syz-extract/fetch.go
parent2119c289682bbbb5fb18049865b43d785e624713 (diff)
sys/syz-extract: parallelize over files
Diffstat (limited to 'sys/syz-extract/fetch.go')
-rw-r--r--sys/syz-extract/fetch.go24
1 files changed, 12 insertions, 12 deletions
diff --git a/sys/syz-extract/fetch.go b/sys/syz-extract/fetch.go
index 2340395cc..604ef2639 100644
--- a/sys/syz-extract/fetch.go
+++ b/sys/syz-extract/fetch.go
@@ -16,10 +16,11 @@ import (
// fetchValues converts literal constants (e.g. O_APPEND) or any other C expressions
// into their respective numeric values. It does so by builting and executing a C program
// that prints values of the provided expressions.
-func fetchValues(arch string, vals []string, includes []string, incdirs []string, defines map[string]string, cflags []string) (map[string]uint64, error) {
- bin, out, err := runCompiler(arch, nil, includes, incdirs, nil, cflags, nil)
+func fetchValues(arch string, vals, includes, incdirs, cflags []string,
+ defines map[string]string) (map[string]uint64, map[string]bool, error) {
+ bin, out, err := runCompiler(arch, nil, includes, incdirs, cflags, nil, nil)
if err != nil {
- return nil, fmt.Errorf("failed to run gcc: %v\n%v", err, string(out))
+ return nil, nil, fmt.Errorf("failed to run gcc: %v\n%v", err, string(out))
}
os.Remove(bin)
@@ -29,7 +30,7 @@ func fetchValues(arch string, vals []string, includes []string, incdirs []string
}
undeclared := make(map[string]bool)
- bin, out, err = runCompiler(arch, vals, includes, incdirs, defines, cflags, undeclared)
+ bin, out, err = runCompiler(arch, vals, includes, incdirs, cflags, defines, undeclared)
if err != nil {
for _, errMsg := range []string{
"error: ‘([a-zA-Z0-9_]+)’ undeclared",
@@ -40,21 +41,20 @@ func fetchValues(arch string, vals []string, includes []string, incdirs []string
for _, match := range matches {
val := string(match[1])
if !undeclared[val] && valMap[val] {
- logf(0, "undefined const: %v", val)
undeclared[val] = true
}
}
}
- bin, out, err = runCompiler(arch, vals, includes, incdirs, defines, cflags, undeclared)
+ bin, out, err = runCompiler(arch, vals, includes, incdirs, cflags, defines, undeclared)
if err != nil {
- return nil, fmt.Errorf("failed to run gcc: %v\n%v", err, string(out))
+ return nil, nil, fmt.Errorf("failed to run gcc: %v\n%v", err, string(out))
}
}
defer os.Remove(bin)
out, err = exec.Command(bin).CombinedOutput()
if err != nil {
- return nil, fmt.Errorf("failed to run flags binary: %v\n%v", err, string(out))
+ return nil, nil, fmt.Errorf("failed to run flags binary: %v\n%v", err, string(out))
}
flagVals := strings.Split(string(out), " ")
@@ -62,7 +62,7 @@ func fetchValues(arch string, vals []string, includes []string, incdirs []string
flagVals = nil
}
if len(flagVals) != len(vals)-len(undeclared) {
- failf("fetched wrong number of values %v != %v - %v\nflagVals: %q\nvals: %q\nundeclared: %q",
+ return nil, nil, fmt.Errorf("fetched wrong number of values %v != %v - %v\nflagVals: %q\nvals: %q\nundeclared: %q",
len(flagVals), len(vals), len(undeclared),
flagVals, vals, undeclared)
}
@@ -77,14 +77,14 @@ func fetchValues(arch string, vals []string, includes []string, incdirs []string
}
n, err := strconv.ParseUint(v, 10, 64)
if err != nil {
- failf("failed to parse value: %v (%v)", err, v)
+ return nil, nil, fmt.Errorf("failed to parse value: %v (%v)", err, v)
}
res[name] = n
}
- return res, nil
+ return res, undeclared, nil
}
-func runCompiler(arch string, vals []string, includes []string, incdirs []string, defines map[string]string, cflags []string, undeclared map[string]bool) (bin string, out []byte, err error) {
+func runCompiler(arch string, vals, includes, incdirs, cflags []string, defines map[string]string, undeclared map[string]bool) (bin string, out []byte, err error) {
includeText := ""
for _, inc := range includes {
includeText += fmt.Sprintf("#include <%v>\n", inc)