diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2021-09-14 19:28:39 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2021-09-16 14:48:44 +0200 |
| commit | e3cdbf8656cad84675862071c60bc9442930fbb1 (patch) | |
| tree | f47044f730af99476bb21c61e66b8970f98b5a56 /sys/syz-extract/fetch.go | |
| parent | 07e953c105af057cb474bc086f68fb7ec5b241ec (diff) | |
sys/syz-extract: restore kvm const extraction for arm64/ppc64
Change #2755 disabled KVM for arm64/ppc64, but KVM is supported on these arches
and has extensive support. It's pity to lose that support.
The real root cause of the problem with arm64/ppc64 is that some severe compilation
errors terminated compilation and did not let compiler spew all error messages.
As the result we did not parse all of them and did not disable all of them.
Re-try compilation multiple times instead of just 2 to fix this.
Update #2754
Diffstat (limited to 'sys/syz-extract/fetch.go')
| -rw-r--r-- | sys/syz-extract/fetch.go | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/sys/syz-extract/fetch.go b/sys/syz-extract/fetch.go index dd0c6aeb3..12c2f5d7d 100644 --- a/sys/syz-extract/fetch.go +++ b/sys/syz-extract/fetch.go @@ -35,16 +35,24 @@ func extract(info *compiler.ConstInfo, cc string, args []string, params *extract Includes: info.Includes, Values: info.Consts, } + bin := "" + missingIncludes := make(map[string]bool) undeclared := make(map[string]bool) - bin, out, err := compile(cc, args, data) - if err != nil { + valMap := make(map[string]bool) + for _, val := range info.Consts { + valMap[val] = true + } + for { + bin1, out, err := compile(cc, args, data) + if err == nil { + bin = bin1 + break + } // Some consts and syscall numbers are not defined on some archs. // Figure out from compiler output undefined consts, // and try to compile again without them. - valMap := make(map[string]bool) - for _, val := range info.Consts { - valMap[val] = true - } + // May need to try multiple times because some severe errors terminate compilation. + tryAgain := false for _, errMsg := range []string{ `error: [‘']([a-zA-Z0-9_]+)[’'] undeclared`, `note: in expansion of macro [‘']([a-zA-Z0-9_]+)[’']`, @@ -55,11 +63,16 @@ func extract(info *compiler.ConstInfo, cc string, args []string, params *extract matches := re.FindAllSubmatch(out, -1) for _, match := range matches { val := string(match[1]) - if valMap[val] { + if valMap[val] && !undeclared[val] { undeclared[val] = true + tryAgain = true } } } + if !tryAgain { + return nil, nil, fmt.Errorf("failed to run compiler: %v %v\n%v\n%s", + cc, args, err, out) + } data.Values = nil for _, v := range info.Consts { if undeclared[v] { @@ -67,15 +80,18 @@ func extract(info *compiler.ConstInfo, cc string, args []string, params *extract } data.Values = append(data.Values, v) } - bin, out, err = compile(cc, args, data) - if err != nil { - return nil, nil, fmt.Errorf("failed to run compiler: %v %v\n%v\n%s", - cc, args, err, out) + data.Includes = nil + for _, v := range info.Includes { + if missingIncludes[v] { + continue + } + data.Includes = append(data.Includes, v) } } defer os.Remove(bin) var flagVals []uint64 + var err error if data.ExtractFromELF { flagVals, err = extractFromELF(bin, params.TargetEndian) } else { |
