aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/compiler
Commit message (Collapse)AuthorAgeFilesLines
* all: use `t.TempDir` to create temporary test directoryEng Zer Jun2022-03-281-5/+1
| | | | | | | | | This commit replaces all `ioutil.TempDir` with `t.TempDir` in tests. The directory created by `t.TempDir` is automatically removed when the test and all its subtests complete. Reference: https://pkg.go.dev/testing#T.TempDir Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
* prog: pass ctx by pointer to ForeachType callbackDmitry Vyukov2022-01-111-2/+2
| | | | | This will allow callbacks to stop iteration early by setting ctx.Stop flag (as it works for ForeachArg).
* pkg/compiler: require stricter resource constructorsDmitry Vyukov2022-01-114-9/+26
| | | | | | | | | | | | | Don't consider syscalls that return resources in unions/arrays as constructors. Unions and arrays are problematic because we don't have directed generation in prog.randGen.createResource() and can fail to generate a syscall that returns a particular resource (generate a wrong union option that does not contain the necessary resource). This leads to the following panics: panic: failed to create a resource ifindex with ioctl$sock_SIOCGIFCONF Require each resource to have a constructor syscall that returns the resource outside of unions/arrays.
* pkg/compiler: fix error message spellingDmitry Vyukov2022-01-112-5/+5
| | | | Add missing space before brackets.
* pkg/compiler: prohibit use of len/flags/const/proc types in out fieldsDmitry Vyukov2022-01-112-1/+10
| | | | These types in explict out fields is either unnecessary details or bugs in descriptions.
* pkg/compiler: prohibit use of direction attribute on union fieldsDmitry Vyukov2022-01-115-20/+19
| | | | | | Direction attributes on unions work in a confusing way and don't do what users may think they do. Now we have out_overlay attribute for structs that allows to have overlapping input and output fields.
* pkg/compiler: add out_overlay field attributeDmitry Vyukov2022-01-117-25/+141
|
* pkg/compiler: refactor codeDmitry Vyukov2022-01-112-13/+18
| | | | | Slightly refactor code in preparation for future changes. No functional changes intended.
* pkg/compiler: warn about confusing comments that fake directivesDmitry Vyukov2021-11-122-0/+19
| | | | | | | | It's a somewhat common mistake to write comments instead of directives: #include <foo> #define FOO BAR because that's how it's done in C. Warn about such cases.
* pkg/compiler: fix almost infinite recursion in template instantiationDmitry Vyukov2021-10-053-25/+48
| | | | | Fix another cases where recurion is finite but fan out factor is large, so our recursion check would take 5^10 iterations to handle this.
* pkg/compiler: add more tests for templatesDmitry Vyukov2021-10-051-0/+20
| | | | Add 2 more tests for recursive templates.
* pkg/compiler: fix infinite recursion in template instantiationDmitry Vyukov2021-10-053-18/+41
| | | | | | | | | | | | | Fix a bug found by OSS-Fuzz: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=17240 We handled the case of infinite recursion in templates but only if the full type name matches precisely (A -> B -> A). In this case the name constantly changes due to different template arguments. Per se this is a not an error (and we have real cases that use this, e.g. when an nlattr_t contains nested nlattr_t's), but it's an error if it recurses infinitely. Restrict recursion on the same template to 10 levels.
* all: minor glob fixesDmitry Vyukov2021-05-261-8/+2
|
* pkg/compiler: add glob typeJoey Jiaojg2021-05-263-2/+32
| | | | | | | | | | | | | | | | | | | | * all: add new typename dirname The current way to check files under sysfs or proc is: - define a string to represent each file - open the file - pass the fd to write / read / close The issues above are: - Need to know what file present on target device - Need to write openat for each file With dirname added, which will open one file in the directory randomly and then pass the fd to write/read/close. * all: use typename glob to match filename Fixes #481
* pkg/compiler: optimize array[const] representationDmitry Vyukov2021-04-211-0/+24
| | | | | | | | | | | | | | Represent array[const[X, int8], N] as string["XX...X"]. This replaces potentially huge number of: NONFAILING(*(uint8_t*)0x2000126c = 0); NONFAILING(*(uint8_t*)0x2000126d = 0); NONFAILING(*(uint8_t*)0x2000126e = 0); with a single memcpy. In one reproducer we had 3991 such lines. Also replace memcpy's with memset's when possible. Update #1070
* pkg/ifuzz/powerpc: add powerpc supportAlexey Kardashevskiy2020-11-201-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | This adds KVM's syz_kvm_setup_cpu pseudo syscall. This adds placeholder for options (none implemented yet). This adds instruction generator for ifuzz; this also adds a few pseudo instructions to simulate super/hyper/ultracalls (a PPC64/pseries platform thing). The insns.go is generated from PowerISA_public.v3.0B.pdf [1] by a horrendous python3 script on top of pdftotext. The ISA covers POWER9 which is the latest available POWER CPU at the moment. The next ISA for POWER10 is quite different and we will deal with it later. The // comment after every instruction is a fixed opcode list for verification purposes. This does not define DecodeExt as there is no obvious replacement of the Intel XED library for POWERPC (gapstone-capstone, later, may be). [1] https://openpowerfoundation.org/?resource_lib=power-isa-version-3-0 Signed-off-by: Alexey Kardashevskiy <aik@linux.ibm.com>
* pkg/compiler: fix crash on invalid templatesDmitry Vyukov2020-11-182-2/+13
| | | | | Discovered by go-fuzz/OSS-Fuzz: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=27599
* pkg/compiler: check for flags with all equal valuesDmitry Vyukov2020-11-132-1/+17
| | | | | | There is no point in having flags when values are equal. This can only mean a typo or other bug. Check for such cases and fix 3 existing precedents.
* pkg/compiler: fix handling of defines with a 0 valueAnton Lindqvist2020-10-311-1/+1
| | | | | | | | | | | | | | | While adding new syscall descriptions to OpenBSD I ran into the following problem: $ gmake extract SOURCEDIR=/home/src && ./bin/syz-sysgen fs.txt.const:15: failed to parse int: strconv.ParseUint: parsing "": invalid syntax $ tail -n +15 sys/openbsd/fs.txt.const | head -1 O_RDONLY = Note that `O_RDONLY` lacks a value and the same directive is defined as 0 on OpenBSD. In `ConstFile.Serialize()`, if val is equal to the default value is has only already been serialized if `max != 0`.
* sys/targets: add OS/Arch name constsDmitry Vyukov2020-10-263-8/+8
| | | | | | | | | | | | We use strings to identify OS/Arch. These strings are duplicated throughout the code base massively. golangci-lint points to possiblity of typos and duplication. We already had to define these names in pkg/csource and disable checking for prog package. A future change triggers such warnings in another package. Add OS/Arch name consts to sys/targets so that they can be used to refer to OS/Arch. Use the consts everywhere.
* pkg/compiler: merge const files into a single fileDmitry Vyukov2020-08-134-117/+425
| | | | | | | | | | | | | | | | | | | | We now have 8 arches for Linux and .const files produce lots of noise in PRs and lots of diffs. If 3 .txt files are touched, the PR will have 24 .const files, which will be intermixed with .txt files. Frequently const values are equal across arches, and even if they don't spreading a single value across 8 files is inconvinient. Merge all 8 *_arch.const files into a single .const file. See the test for details of the new format. The old format is still parsed for now, we can't update all OSes at once. For Linux this reduces number of const files/lines from 1288/96599 to 158/11603. Fixes #1983
* pkg, prog: add per-field direction attributeNecip Fazil Yildiran2020-08-136-9/+155
|
* pkg/compiler: check for unused resourcesDmitry Vyukov2020-08-042-10/+27
| | | | | | | | | | If a resource is never used as an input, it is not useful. It's effectively the same as using an integer. Detect such cases, they are quite confusing. Fix all existing errors in descriptions. This uncovered some interesting bugs as well, e.g. use of a completely unrelated fd subtype after copy-paste (while the resource that was supposed to be used there is completely unused).
* pkg/compiler: fix crash on fmt[flags]Dmitry Vyukov2020-07-232-0/+9
| | | | | | | Flags with only 1 value 0 are transformed to ConstType. Fmt did not expect that. Fixes #1965
* prog/types.go: add Type.Alignment() and TypeCommon.TypeAlignAlbert van der Linde2020-07-142-53/+46
| | | | | Type.Alignment() can be used to obtain byte alignment for correctly allocating aligned memory for the Type.
* all: fix comments formatDmitry Vyukov2020-07-121-2/+2
| | | | | | | Fix capitalization, dots at the end and two spaces after a period. Update #1876
* all: fix dup types in func argsDmitry Vyukov2020-07-041-1/+1
|
* .golangci.yml: make goconst checker more strictDmitry Vyukov2020-06-071-3/+5
|
* .golangci.yml: reduce scope of suppressionsDmitry Vyukov2020-06-071-2/+1
| | | | | Reduce scope of some suppressions (some are violated only in some packages). Remove some outdated, fix and enable the type switch warning.
* pkg/compiler: remove unused statementDmitry Vyukov2020-06-051-1/+0
|
* sys/syz-extract: use -nostdinc on linuxDmitry Vyukov2020-05-111-0/+2
| | | | This makes the build completely hermetic.
* prog: refactor ANY to not fabricate new typesDmitry Vyukov2020-05-051-0/+23
| | | | | | | | | | Currently ANY implementation fabricates new types dynamically. This is something we don't do anywhere else, generally types come from compiler and all are static. Dynamic types will conflict with use of Ref in Arg optimization. Move ANY types creation into compiler. Update #1580
* pkg/compiler: simplify and enhance handling of builtinsDmitry Vyukov2020-05-055-35/+23
| | | | | | | | | Currently we have special support for each type of builtin node. This is complex and does not scale (we may want other types in future). Prepend the builtin descriptions to the user descriptions instead. This requires a bit of special support, like not reporting any builtin descriptions as unused, but otherwise much simpler and more flexible. Does not produce any diff in generated descriptions.
* prog: remove StructDescDmitry Vyukov2020-05-034-202/+108
| | | | | | | | | | | | 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
* prog: introduce Field typeDmitry Vyukov2020-05-024-46/+49
| | | | | | | | | | | | | 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
* prog: rename {PtrType,ArrayType}.Type to ElemDmitry Vyukov2020-05-012-10/+10
| | | | | | | 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.
* prog: remove Dir from TypeDmitry Vyukov2020-05-014-39/+33
| | | | | | | | | | | | | | | | | | Having Dir is Type is handy, but forces us to duplicate lots of types. E.g. if a struct is referenced as both in and out, then we need to have 2 copies and 2 copies of structs/types it includes. If also prevents us from having the struct type as struct identity (because we can have up to 3 of them). Revert to the old way we used to do it: propagate Dir as we walk syscall arguments. This moves lots of dir passing from pkg/compiler to prog package. Now Arg contains the dir, so once we build the tree, we can use dirs as before. Reduces size of sys/linux/gen/amd64.go from 6058336 to 5661150 (-6.6%). Update #1580
* pkg/compiler: deduplicate Types in descriptionsDmitry Vyukov2020-04-262-1/+74
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* pkg/compiler: simplify sort predicateDmitry Vyukov2020-04-251-4/+4
|
* all: fix liner errorsDmitry Vyukov2020-04-191-8/+8
| | | | | | | | | | | | pkg/compiler/compiler.go:182: line is 125 characters func (comp *compiler) parseAttrs(descs map[string]*attrDesc, parent ast.Node, attrs []*ast.Type) (res map[*attrDesc]uint64) { sys/targets/common.go:47:21: unnecessary conversion makeMmap(^uint64(target.PageSize)+1, target.PageSize, 0), ^ sys/targets/common.go:61: File is not `gofmt`-ed with `-s` &prog.Call{ sys/windows/init.go:35: File is not `gofmt`-ed with `-s` &prog.Call{
* pkg/compiler: error on duplicate attributesDmitry Vyukov2020-04-192-0/+5
|
* prog: introduce call attributesDmitry Vyukov2020-04-196-30/+75
| | | | | | Add common infrastructure for syscall attributes. Add few attributes we want, but they are not implemented for now (don't affect behavior, this will follow).
* pkg/compiler: refactor attribute handlingDmitry Vyukov2020-04-198-139/+179
| | | | | | | | | | | | Introduce common infrastructure for describing and parsing attribute instead of custom per-attribute code scattered across several locations. Change align attribute syntax from the weird align_N to align[N]. This also allows to use literal constants as N. Introduce notion of builtin constants. Currently we have only PTR_SIZE, which is needed to replace align_ptr with align[PTR_SIZE].
* prog: add MaxArgs constDmitry Vyukov2020-03-311-3/+2
| | | | | Move the const from the compiler. In preparation for future changes.
* pkg/compiler: truncate const values to their physical sizeDmitry Vyukov2020-03-241-1/+3
| | | | | | We do similar truncation for values in the prog package (truncateToBitSize). Truncating them in the generated descriptions makes it possible to directly compare values (otherwise -1 and truncated -1 don't match).
* pkg/compiler: check that flags values fit into base typeDmitry Vyukov2020-03-173-15/+37
| | | | | | | | flags[foo, int8] foo = 0x12345678 is always an error, detect these cases. Found some bugs in mptcp, packet sockets, kvm.
* pkg/compiler: preserve literal int const namesDmitry Vyukov2020-03-171-11/+19
| | | | Useful for error reporting.
* pkg/compiler: reduce clutter in test outputDmitry Vyukov2020-03-171-1/+5
| | | | Don't prefix each error with test file:line (which is pointless in this case).
* pkg/compiler: check that const values fit into base typeDmitry Vyukov2020-03-174-46/+53
| | | | | const[0x12345678, int8] is always an error, detect these cases. Found some bugs in mptcp, socket proto and fuchsia fidl descriptions.
* pkg/compiler: unshare error handlerDmitry Vyukov2020-03-171-0/+3
| | | | | eh is shared across several tests and uses wrong t. Unshare it.