aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/compiler/consts.go
Commit message (Collapse)AuthorAgeFilesLines
* pkg/declextract: remove unused includes and definesDmitry Vyukov2025-01-171-4/+9
| | | | | | | | | | This is nice on its own, but this will also help to prevent lots of problems when we export more info from the clang tool in future. The clang tool does not know what will end up in the final descriptions, so it exports info about all consts that it encounters. As the result we pull in lots of includes/defines, and lots of kernel includes/defines are broken or create problems. So the fewer we have, the better.
* pkg/compiler: add automatic metaDmitry Vyukov2024-12-111-1/+1
| | | | | | Mark the whole file with "meta automatic" instead of marking each syscall. This reduces size of descriptions + allows to do special things with the whole file (e.g. we already treat auto consts specially).
* pkg/compiler: allow manual consts to override auto-extracted constsDmitry Vyukov2024-11-261-1/+1
| | | | | | | | | | | | | | | | | | | | Currently if const values in 2 .const files have different value, the compiler produces an error. This is problematic for auto-extacted consts since we extract them for only 1 arch now. So if a const has different values for different arches, auto-extacted consts may not reflect that, and we can get a mismatch with manual descriptions that has correct values for all arches. So if both manual and auto-extacted consts have different values, silently prefer the manual ones. I've tried to do some whitelisting of consts during auto-extaction, but the list is large and changing over time. This solution is not perfect since the manual descriptions may have a bug, and the mismatch is actually pointing to that bug. Maybe in future we could extract for all arches separately, or do something else. But let's do this for now.
* pkg/compiler: add consts to all files that mention themDmitry Vyukov2024-11-131-33/+57
| | | | | | | | | We already do this in most cases except for template structs (nlattr notably). Add consts that are used in template structs to all files that use them. This helps to avoid flakiness, and allows to replace descriptions files with other descriptions files without regenerating all const files. This also fixes check for presence of descriptions for sys/linux/auto.txt.json.
* pkg/compiler: support if[expr] attributesAleksandr Nogikh2024-02-191-5/+39
| | | | | | | | | | | | | | | | | | | The expression may either include integers/consts or reference other fields in the structure via value[field1:field2:field3]. The fields on this path must all belong to structures and must not have any if conditions themselves. For unions, mandate that the last field has no conditions (it will be the default one). For structs, convert conditional fields into fields of a union type of the following form: anonymous_union [ value T (if[expression]) void void ]
* compiler: support flags as int first argumentPaul Chaignon2023-11-281-0/+12
| | | | | | | | | | | | | | | | | | | This commit adds support for the following syntax: int_flags = 1, 5, 8, 9 int32[int_flags] which is equivalent to: int_flags = 1, 5, 8, 9 flags[int_flags, int32] The second int type argument, align, is not allowed if the first argument is a flag. The compiler will also error if the first argument appears to be a flag (is ident and has no colon), but can't be found in the map of flags. Signed-off-by: Paul Chaignon <paul.chaignon@gmail.com>
* compiler: support type args with mixed kindsPaul Chaignon2023-11-281-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | Type args can currently have only one type of kindInt, kindIdent, kindString, or kindAny. The descriptions are checked against expected type arg kinds, with kindAny meaning that anything is allowed (often restricted with custom checks). Concretely, it means that in a description as follows, arg1 and arg2 can each take a single kind of values. type[arg1, arg2] This is limiting if we want arg1 to be able to take both an int or flags. We thus need type args to support having mixed kinds. This commit achieves this by turning the kind constants into bit flags. This will be useful in a subsequent commit, but we can also already use it for one existing type arg, the first of string types: string[literal_or_flags, size] literal_or_flags changes from kindAny to kindIdent|kindString and we can remove the custom check that used to enforce this. Signed-off-by: Paul Chaignon <paul.chaignon@gmail.com>
* sys: refactor const extractionAleksandr Nogikh2023-10-041-13/+30
| | | | | 1) Make FabricateSyscallConsts() operate on ConstFile. 2) Expose Pos inside ConstInfo.
* sys/targets: introduce HasCallNumber to reduce clutterGreg Steuck2023-04-251-1/+1
| | | | This centralizes all strings.HasPrefix(callName, "syz_") checks.
* pkg/compiler: merge const files into a single fileDmitry Vyukov2020-08-131-116/+0
| | | | | | | | | | | | | | | | | | | | 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
* .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.
* sys/syz-extract: use -nostdinc on linuxDmitry Vyukov2020-05-111-0/+2
| | | | This makes the build completely hermetic.
* pkg/compiler: simplify and enhance handling of builtinsDmitry Vyukov2020-05-051-0/+3
| | | | | | | | | 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: introduce call attributesDmitry Vyukov2020-04-191-30/+34
| | | | | | 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-191-13/+30
| | | | | | | | | | | | 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].
* pkg/compiler: preserve literal int const namesDmitry Vyukov2020-03-171-11/+19
| | | | Useful for error reporting.
* pkg/compiler: don't specify syscall consts for test OSDmitry Vyukov2020-03-171-0/+15
| | | | This is just tedious. Fabricate them on the fly.
* pkg/compiler: work around 0-array-size errors due to missing constsDmitry Vyukov2019-05-151-10/+17
| | | | | | | A const can be used as array size. Then if the const is not present on all arches, compiler will produce an error about 0-sized-array. There is no easy way to work around this for a user. Use value of 1 for missing consts. It's just a bit safer.
* pkg/ast: refactor COLON handlingDmitry Vyukov2019-05-141-6/+8
| | | | | | | This prepared for handling of bytesize[parent:foo:bar] expressions by allowing multiple identifiers after colon. No functional changes for now, just preparation for storing more than one identifier after colon.
* prog, pkg/compiler: fix warningsDmitry Vyukov2019-03-291-1/+2
| | | | | | | | | | | | | gometalinter says: pkg/compiler/consts.go:192::warning: internal error: no range for "n" (vetshadow) pkg/compiler/consts.go:197::warning: internal error: no range for "n" (vetshadow) prog/encoding.go:862::warning: declaration of "v" shadows declaration at prog/encoding.go:852 (vetshadow) This somehow happens only with Go1.11 but not 1.12 so wasn't detected locally. The prog warnings looks legit. The pkg/compiler warning was amusingly introduced to please golangci-lint checker, revert that fix for now.
* all: fix warnings pointed to by golangci-lintDmitry Vyukov2019-03-281-2/+1
| | | | Update #977
* gometalinter: clean up vetshadowDmitry Vyukov2018-07-311-1/+1
| | | | | | | This just cleans up existing warnings. vetshadow is not enabled yet because it crashes. Update #538
* gometalinter: some fixes for unparamDmitry Vyukov2018-05-031-10/+6
| | | | | | But we still can't enable it as there are more [uninteresting] warnings. Update #538
* pkg/compiler: support size attribute for unionsDmitry Vyukov2018-03-051-2/+2
|
* pkg/compiler: add size attribute for structsDmitry Vyukov2018-03-051-0/+21
| | | | The size attribute allows to pad a struct up to the specified size.
* sys/syz-extract: save unsupported consts to the const filesDmitry Vyukov2018-02-011-10/+13
| | | | | | | | | | | We currently print unsupported consts to console during make extract. But this is not very useful as there are too many output now. This also does not allow to understand what's unsupported in newly checked-in descriptions, or what's unsupported in all current decriptions. Save unsupported consts to the const files instead. This solves all of the above problems.
* sys/syz-sysgen: don't generate syz_ syscall numbersDmitry Vyukov2018-01-131-29/+1
| | | | They don't seem to be used today.
* pkg/compiler: support type templatesDmitry Vyukov2018-01-131-136/+122
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Netlink descriptions contain tons of code duplication, and need much more for proper descriptions. Introduce type templates to simplify writing such descriptions and remove code duplication. Note: type templates are experimental, have poor error handling and are subject to change. Type templates can be declared as follows: ``` type buffer[DIR] ptr[DIR, array[int8]] type fileoff[BASE] BASE type nlattr[TYPE, PAYLOAD] { nla_len len[parent, int16] nla_type const[TYPE, int16] payload PAYLOAD } [align_4] ``` and later used as follows: ``` syscall(a buffer[in], b fileoff[int64], c ptr[in, nlattr[FOO, int32]]) ```
* pkg/ast: refactor WalkDmitry Vyukov2018-01-111-5/+5
| | | | | Refactor Walk so that it's possible to abort or wrap walk of child nodes. Will be needed for future changes.
* sys: support type aliases (aka typedefs)Dmitry Vyukov2018-01-081-2/+2
| | | | | | | | | | | | | | | | | | | | | | Complex types that are often repeated can be given short type aliases using the following syntax: ``` type identifier underlying_type ``` For example: ``` type signalno int32[0:65] type net_port proc[20000, 4, int16be] ``` Then, type alias can be used instead of the underlying type in any contexts. Underlying type needs to be described as if it's a struct field, that is, with the base type if it's required. However, type alias can be used as syscall arguments as well. Underlying types are currently restricted to integer types, `ptr`, `ptr64`, `const`, `flags` and `proc` types.
* pkg/csource: support akarosDmitry Vyukov2017-10-161-7/+4
|
* all: basic freebsd supportDmitry Vyukov2017-10-021-2/+4
| | | | For now we just make Go part build for freebsd.
* sys/syz-extract: support fuchsiaDmitry Vyukov2017-09-251-2/+3
|
* all: more assorted fuchsia supportDmitry Vyukov2017-09-221-0/+5
|
* pkg/compiler: don't genererate missing syscallsDmitry Vyukov2017-09-151-16/+5
| | | | | | | | We used to generate them only because manager had no idea what arch it is testing. So syscalls numbers had to match between all arches. This is not needed anymore. Also don't generate unreferenced structs/resources.
* pkg/compiler: restore generation of unsupported syscallsDmitry Vyukov2017-09-021-1/+14
| | | | | | Unfortunately this is sitll needed, see the added comment. Update #191
* pkg/compiler: check and generate typesDmitry Vyukov2017-09-021-12/+175
| | | | | | Move most of the logic from sysgen to pkg/compiler. Update #217
* pkg/compiler: more static error checkingDmitry Vyukov2017-08-271-0/+77
| | | | Update #217
* pkg/compiler: move more const-processing code to compilerDmitry Vyukov2017-08-271-0/+124