aboutsummaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2021-09-14 19:28:39 +0200
committerDmitry Vyukov <dvyukov@google.com>2021-09-16 14:48:44 +0200
commite3cdbf8656cad84675862071c60bc9442930fbb1 (patch)
treef47044f730af99476bb21c61e66b8970f98b5a56 /sys
parent07e953c105af057cb474bc086f68fb7ec5b241ec (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')
-rw-r--r--sys/syz-extract/fetch.go38
-rw-r--r--sys/syz-extract/linux.go12
-rw-r--r--sys/syz-sysgen/sysgen.go3
3 files changed, 33 insertions, 20 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 {
diff --git a/sys/syz-extract/linux.go b/sys/syz-extract/linux.go
index c72e4b559..e4f8d1bfe 100644
--- a/sys/syz-extract/linux.go
+++ b/sys/syz-extract/linux.go
@@ -114,13 +114,11 @@ func (*linux) prepareArch(arch *Arch) error {
func (*linux) processFile(arch *Arch, info *compiler.ConstInfo) (map[string]uint64, map[string]bool, error) {
if strings.HasSuffix(info.File, "_kvm.txt") &&
- arch.target.Arch != targets.I386 && arch.target.Arch != targets.AMD64 {
- // Hack:
- // include/uapi/linux/kvm.h has definitions that can only be compiled under i386
- // and amd64 (e.g. KVM_SET_CPUID). On all other arches they generate build errors
- // and therefore this tool is not able to proceed.
- // TODO: remove this once #2754 is resolved.
- // Note: syz-sysgen also ignores this file.
+ (arch.target.Arch == targets.ARM || arch.target.Arch == targets.RiscV64) {
+ // Hack: KVM is not supported on ARM anymore. We may want some more official support
+ // for marking descriptions arch-specific, but so far this combination is the only
+ // one. For riscv64, KVM is not supported yet but might be in the future.
+ // Note: syz-sysgen also ignores this file for arm and riscv64.
return nil, nil, nil
}
headerArch := arch.target.KernelHeaderArch
diff --git a/sys/syz-sysgen/sysgen.go b/sys/syz-sysgen/sysgen.go
index dd64be8d4..35bea4f3b 100644
--- a/sys/syz-sysgen/sysgen.go
+++ b/sys/syz-sysgen/sysgen.go
@@ -117,8 +117,7 @@ func main() {
if OS == targets.Linux && (job.Target.Arch == targets.ARM || job.Target.Arch == targets.RiscV64) {
// Hack: KVM is not supported on ARM anymore. On riscv64 it
// is not supported yet but might be in the future.
- // Note: syz-extract ignores this file on all arches except
- // i386 and amd64 (due to const extraction problems).
+ // Note: syz-extract also ignores this file for arm and riscv64.
top = descriptions.Filter(func(n ast.Node) bool {
pos, _, _ := n.Info()
return !strings.HasSuffix(pos.File, "_kvm.txt")