Commit Graph

25 Commits

Author SHA1 Message Date
Dmitry Vyukov
58ae5e1862 prog: remove StructDesc
Remove StructDesc, KeyedStruct, StructKey and all associated
logic/complexity in prog and pkg/compiler.
We can now handle recursion more generically with the Ref type,
and Dir/FieldName are not a part of the type anymore.
This makes StructType/UnionType simpler and more natural.

Reduces size of sys/linux/gen/amd64.go from 5201321 to 4180861 (-20%).

Update #1580
2020-05-03 12:55:42 +02:00
Dmitry Vyukov
58da4c35b1 prog: introduce Field type
Remvoe FieldName from Type and add a separate Field type
that holds field name. Use Field for struct fields, union options
and syscalls arguments, only these really have names.

Reduces size of sys/linux/gen/amd64.go from 5665583 to 5201321 (-8.2%).
Allows to not create new type for squashed any pointer.
But main advantages will follow, e.g. removing StructDesc,
using TypeRef in Arg, etc.

Update #1580
2020-05-02 12:16:06 +02:00
Dmitry Vyukov
bc734e7ada prog: rename {PtrType,ArrayType}.Type to Elem
Name "Type" is confusing when referring to pointer/array element type.
Frequently there are too many Type/typ/typ1/t and typ.Type is not very informative.
It _is_ a type, but what's usually more relevant is that it's an _element_ type.
Let's leave type checking to compiler and give it a more meaningful name.
2020-05-01 13:31:17 +02:00
Dmitry Vyukov
136082ab38 pkg/cmdprof: add package
cmdprof simplifies cpu/memory profiling for command line tools. Use as:

	flag.Parse()
	defer cmdprof.Install
2020-04-30 17:18:29 +02:00
Dmitry Vyukov
0ce7569ee7 pkg/compiler: deduplicate Types in descriptions
Add prog.Ref Type that serves as a proxy for real types
and allows to deduplicate Types in generated descriptions.
The Ref type is effectively an index in an array of types.
Just before serialization pkg/compiler replaces real types
with the Ref types and prepares corresponding array of real types.
When a Target is registered in prog package, we do the opposite
operation and replace Ref's with the corresponding real types.

This brings improvements across the board:
compiler memory consumption is reduced by 15%,
test building time by 25%, descriptions size by 33%.

Before:
$ du -h sys/linux/gen
54M	sys/linux/gen

$ time GOMAXPROCS=1 go test -p=1 -c ./prog
real	0m54.200s
real	0m53.883s

$ time GOMAXPROCS=1 go install -p=1 ./tools/syz-execprog
real	0m27.911s
real	0m27.767s

$ TIME="%e %P %M" GOMAXPROCS=1 time go tool compile ./sys/linux/gen
20.59 100% 3200016
20.97 100% 3445976
20.25 100% 3209684

After:
$ du -h sys/linux/gen
36M	sys/linux/gen

$ time GOMAXPROCS=1 go test -p=1 -c ./prog
real	0m42.290s
real	0m43.230s

$ time GOMAXPROCS=1 go install -p=1 ./tools/syz-execprog
real	0m24.337s
real	0m24.727s

$ TIME="%e %P %M" GOMAXPROCS=1 time go tool compile ./sys/linux/gen
19.11 100% 2764952
19.66 100% 2787624
19.35 100% 2749376

Update #1580
2020-04-26 05:58:31 +02:00
Dmitry Vyukov
0a96a13cb9 tools/syz-check: extend usage docs
Allow to run for only 1 arch and extend docs.
2020-03-18 09:23:24 +01:00
Dmitry Vyukov
05359321bb all: fix new golangci-lint warnings
Newer version started producing more warnings. Fix them.
2020-03-13 08:26:02 +01:00
Dmitry Vyukov
5e48183c6e sys/linux: add ethtool netlink descriptions 2020-01-28 15:08:47 +01:00
Dmitry Vyukov
0e8428d26f tools/syz-check: add limited checking of varlen structs
Stop at the fist varlen field, but check the preceeding ones.
Frequently the varlen array is the last field,
so we should get good checking for these cases.

Update #590
2020-01-23 15:05:21 +01:00
Dmitry Vyukov
9ab9b329d9 sys/linux: check for missing/duplicate netlink attrs
Update #590
2020-01-23 15:05:20 +01:00
Dmitry Vyukov
46961c2ff5 sys/linux: fix more netlink warnings
Handle NLA_BITFIELD32.
Match string attribtues better.
Calculate and check min size for varlen structs.
Fix NLA_UNSPEC size check.
Fix some things in descriptions.

Update #590
2020-01-23 15:05:19 +01:00
Dmitry Vyukov
e4c56f390e tools/syz-check: improve matching netlink attributes
1. Match policies that has a _suffix in our descriptions
(we frequently do this to improve precision or avoid dup names).
2. Rename policies in descriptions to match kernel names.
3. Match policy if there are several such names in kernel.
4. Recognize policies with helper sub-policies.

Update #590
2020-01-22 18:31:15 +01:00
Dmitry Vyukov
02754a8f9a tools/syz-check: check netlink policy descriptions
Overall idea of netlink checking.
Currnetly we check netlink policies for common detectable mistakes.
First, we detect what looks like a netlink policy in our descriptions
(these are structs/unions only with nlattr/nlnext/nlnetw fields).
Then we find corresponding symbols (offset/size) in vmlinux using nm.
Then we read elf headers and locate where these symbols are in the rodata section.
Then read in the symbol data, which is an array of nla_policy structs.
These structs allow to easily figure out type/size of attributes.
Finally we compare our descriptions with the kernel policy description.

Update #590
2020-01-22 12:19:53 +01:00
Dmitry Vyukov
d2f8d5ab46 sys/linux: fix sigset_t/sigaction layout on arm
Update #590
2020-01-18 21:02:24 +01:00
Dmitry Vyukov
773117bf81 tools/syz-check: also check arm/arm64
They mostly duplicate the warnings we already have for amd64/386.
But uncovered few very interesting local things (e.g. epoll_event
is packed only on amd64, so arm/arm64 layout is wrong, but 386
is correct because int64 alignment is different).

Update #590
2020-01-18 21:02:24 +01:00
Dmitry Vyukov
61f4e7ee54 tools/syz-check: check amd64 and 386 at the same time
Update #590
2019-12-22 19:34:12 +01:00
Dmitry Vyukov
c5907f7c7a tools/syz-check: check templates
Also rename some netfilter types to eliminate massive amounts of template warnings.

Update #590
2019-12-22 11:19:49 +01:00
Dmitry Vyukov
1461be9d82 tools/syz-check: add some TODOs 2019-12-22 10:15:24 +01:00
Dmitry Vyukov
f83f92fd5e tools/syz-check: inject description compilation warnings
Currently we print them as part of `make genereate`,
but nobody reads them, too much output each time.
Don't print them in `make generate` and instead
print in syz-check, the warn files are a good mechanism
to handle "known warnings".
2019-12-20 16:45:34 +01:00
Dmitry Vyukov
ae5ed0b140 pkg/compiler: fix bitfield layout bug
Fixes #1542

Found thanks to syz-check. Update #590
2019-12-20 16:45:34 +01:00
Dmitry Vyukov
20c6855484 prog: refactor bitfields representation
All callers of BitfieldMiddle just want static size (0 for middle).
Make it so: Size for middle bitfields just returns 0. Removes lots of if's.
Introduce Type.UnitSize, which now holds the underlying type for bitfields.
This will be needed to fix #1542 b/c even if UnitSize=4 for last bitfield
Size can be anywhere from 0 to 4 (not necessary equal to UnitSize due to overlapping).
2019-12-19 19:32:45 +01:00
Dmitry Vyukov
fa33c32796 tools/syz-check: don't print our/kernel field name twice if equal 2019-12-18 12:04:56 +01:00
Dmitry Vyukov
6462728414 tools/syz-check: print descriptions compilation errors
If one changes descriptions concurrently with re-running syz-check,
it's likely something won't compile first time. Print errors.
2019-12-18 11:58:49 +01:00
Dmitry Vyukov
1b49002e79 tools/syz-check: don't print line numbers for warnings
Line numbers create huge diffs when lines change slightly.
That's very unhandy b/c we want to look at added/removed warnings.
2019-12-18 10:50:24 +01:00
Dmitry Vyukov
64ca0a3711 tools/syz-check: add description checking utility
syz-check parses vmlinux dwarf, extracts struct descriptions,
compares them with what we have (size, fields, alignment, etc)
and produces .warn files.
This is first raw version, it can be improved in a number of ways.
But it already helped to identify a critical issue #1542
and shows some wrong struct descriptions.

Update #590
2019-12-17 19:03:39 +01:00