aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/ifuzz/x86
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2025-04-03 14:35:27 +0200
committerDmitry Vyukov <dvyukov@google.com>2025-04-03 13:17:55 +0000
commitd7ae3a111bd75df44dda69b37da945b50d5133e2 (patch)
tree9797c351f3f4d30ae71068ae1447b457506afb7c /pkg/ifuzz/x86
parent012c639d904cf60a221b8b16833c02eed9b2514e (diff)
pkg/ifuzz: fix generate/build
Currently the commands we have in go:generate first create an empty file and then write final contents. This breaks any parallel builds of the source. Even running go generate ./... does not work. Write output files atomically.
Diffstat (limited to 'pkg/ifuzz/x86')
-rw-r--r--pkg/ifuzz/x86/gen/gen.go14
-rw-r--r--pkg/ifuzz/x86/x86.go2
2 files changed, 11 insertions, 5 deletions
diff --git a/pkg/ifuzz/x86/gen/gen.go b/pkg/ifuzz/x86/gen/gen.go
index dc77ea497..c1af7a44e 100644
--- a/pkg/ifuzz/x86/gen/gen.go
+++ b/pkg/ifuzz/x86/gen/gen.go
@@ -7,6 +7,7 @@ package main
import (
"bufio"
+ "bytes"
"errors"
"fmt"
"os"
@@ -16,14 +17,15 @@ import (
"github.com/google/syzkaller/pkg/ifuzz/iset"
"github.com/google/syzkaller/pkg/ifuzz/x86"
+ "github.com/google/syzkaller/pkg/osutil"
"github.com/google/syzkaller/pkg/serializer"
"github.com/google/syzkaller/pkg/tool"
)
// nolint: gocyclo, gocognit, funlen, dupl
func main() {
- if len(os.Args) != 2 {
- tool.Failf("usage: gen instructions.txt")
+ if len(os.Args) != 3 {
+ tool.Failf("usage: gen instructions.txt output.file")
}
f, err := os.Open(os.Args[1])
if err != nil {
@@ -168,7 +170,8 @@ nextInsn:
fmt.Fprintf(os.Stderr, "deduped %v instructions\n", len(insns)-len(deduped))
insns = deduped
- fmt.Printf(`
+ out := new(bytes.Buffer)
+ fmt.Fprintf(out, `
// Code generated by pkg/ifuzz/x86/gen. DO NOT EDIT.
//go:build !codeanalysis
@@ -183,7 +186,10 @@ func init() {
var insns =
`)
- serializer.Write(os.Stdout, insns)
+ serializer.Write(out, insns)
+ if err := osutil.WriteFileAtomically(os.Args[2], out.Bytes()); err != nil {
+ tool.Fail(err)
+ }
fmt.Fprintf(os.Stderr, "handled %v, skipped %v\n", len(insns), skipped)
}
diff --git a/pkg/ifuzz/x86/x86.go b/pkg/ifuzz/x86/x86.go
index a2825b9e5..053497176 100644
--- a/pkg/ifuzz/x86/x86.go
+++ b/pkg/ifuzz/x86/x86.go
@@ -1,7 +1,7 @@
// Copyright 2017 syzkaller project authors. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
-//go:generate bash -c "go run gen/gen.go gen/all-enc-instructions.txt > generated/insns.go"
+//go:generate go run gen/gen.go gen/all-enc-instructions.txt generated/insns.go
// Package x86 allows to generate and mutate x86 machine code.
package x86