aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2024-10-24 14:33:36 +0200
committerDmitry Vyukov <dvyukov@google.com>2024-10-25 07:56:49 +0000
commit58bd906d601cde032f83f00e29676146a2f5104a (patch)
tree9cebe7fbd9add2ac5119cbd5e9e71676603c50f6 /tools
parenta316ebdbff3a501a1b041a488b2f22c8783df5f8 (diff)
tools/syz-declextract: make fixed header more readable
Combine all fixed header parts in a single raw string literal.
Diffstat (limited to 'tools')
-rw-r--r--tools/syz-declextract/run.go33
1 files changed, 18 insertions, 15 deletions
diff --git a/tools/syz-declextract/run.go b/tools/syz-declextract/run.go
index a680ea12c..40d6497bb 100644
--- a/tools/syz-declextract/run.go
+++ b/tools/syz-declextract/run.go
@@ -157,6 +157,16 @@ func getMinimalOutput(out string, syscallNames map[string][]string) []string {
}
func makeOutput(nodes []ast.Node) []byte {
+ header := `
+# Code generated by syz-declextract. DO NOT EDIT.
+include <include/vdso/bits.h>
+include <include/linux/types.h>
+_ = __NR_mmap2
+`
+ eh := ast.LoggingHandler
+ desc := ast.Parse([]byte(header), "", eh)
+ nodes = append(nodes, desc.Nodes...)
+
slices.SortFunc(nodes, func(a, b ast.Node) int {
return strings.Compare(ast.SerializeNode(a), ast.SerializeNode(b))
})
@@ -179,7 +189,7 @@ func makeOutput(nodes []ast.Node) []byte {
continue
}
structs = append(structs, node)
- case *ast.Include, *ast.TypeDef, *ast.Resource, *ast.IntFlags, *ast.NewLine:
+ case *ast.Include, *ast.TypeDef, *ast.Resource, *ast.IntFlags, *ast.NewLine, *ast.Comment:
continue
default:
_, typ, _ := node.Info()
@@ -203,13 +213,6 @@ func makeOutput(nodes []ast.Node) []byte {
return a.Name.Name == b.Name.Name
})
- autoGeneratedNotice := "# Code generated by syz-declextract. DO NOT EDIT.\n"
- commonKernelHeaders := "include <include/vdso/bits.h>\ninclude <include/linux/types.h>"
- var netlinkNames []string
- mmap2 := "_ = __NR_mmap2\n"
- eh := ast.LoggingHandler
- desc := ast.Parse([]byte(autoGeneratedNotice+commonKernelHeaders), "", eh)
- desc.Nodes = append(desc.Nodes, nodes...)
usedNetlink := make(map[string]bool)
for _, node := range syscalls {
if node.CallName == sendmsg && len(node.Args[1].Type.Args) == 2 && len(node.Args[1].Type.Args[1].Args) > 1 {
@@ -222,11 +225,11 @@ func makeOutput(nodes []ast.Node) []byte {
continue
}
}
- desc.Nodes = append(desc.Nodes, node)
+ nodes = append(nodes, node)
}
- desc.Nodes = append(desc.Nodes, ast.Parse([]byte(mmap2), "", eh).Nodes...)
+ var netlinkNames []string
for _, node := range structs {
- desc.Nodes = append(desc.Nodes, node)
+ nodes = append(nodes, node)
name := node.Name.Name
if !usedNetlink[name] && !strings.HasSuffix(name, "$auto_record") {
netlinkNames = append(netlinkNames, name)
@@ -246,11 +249,11 @@ auto_union [
if netlinkUnionParsed == nil {
tool.Failf("parsing error")
}
- desc.Nodes = append(desc.Nodes, netlinkUnionParsed.Nodes...)
+ nodes = append(nodes, netlinkUnionParsed.Nodes...)
- // New lines are added in the parsing step. This is why we need to Format (serialize the description), Parse, then
- // Format again.
- return ast.Format(ast.Parse(ast.Format(desc), "", eh))
+ // New lines are added in the parsing step. This is why we need to Format (serialize the description),
+ // Parse, then Format again.
+ return ast.Format(ast.Parse(ast.Format(&ast.Description{nodes}), "", eh))
}
func worker(outputs chan output, files chan string, binary, compilationDatabase, format string) {