aboutsummaryrefslogtreecommitdiffstats
path: root/tools/syz-declextract/clangtool/declextract.cpp
Commit message (Collapse)AuthorAgeFilesLines
* tools/clang/declextract: move from tools/syz-declextract/clangtoolDmitry Vyukov2025-11-171-1009/+0
| | | | | Some of the common helpers may be reused across different Clang tools (currently json.h and .clang-format). Move the files to allow such reuse.
* tools/syz-declextract: update clangtool to the latest clangDmitry Vyukov2025-11-171-6/+5
| | | | Fix some minor API changes.
* tools/syz-declextract: extract function references more preciselyDmitry Vyukov2025-04-151-13/+22
| | | | | | Currently we misparse some function references, e.g. for: .write = (foo) ? bar : baz, we extract "foo". Extract first function reference from such expressions.
* tools/syz-declextract: extract enums declared with a typedefDmitry Vyukov2025-04-151-4/+18
|
* tools/syz-declextract: extract ioctls declared with enumsDmitry Vyukov2025-04-151-28/+37
| | | | | Some ioctls are declared inconsistently using enums rather than macros. Extract these as well.
* tools/syz-declextract: add interface coverage infoDmitry Vyukov2025-04-101-1/+4
| | | | | | Add coverage percent for kernel interfaces. The current data is generated with Mar coverage report on kernel commit 1e7857b28020ba57ca7fdafae7ac855ba326c697.
* pkg/declextract: export syscall variants as separate interfacesDmitry Vyukov2025-04-101-20/+12
| | | | | | Export each syscall variant (e.g. fcnt$*) as a separate interface. Effectively these are separate syscalls. We will want this for ioctl as well (it's not 1 interface).
* tools/syz-declextract: handle ints more carefullyDmitry Vyukov2025-04-101-1/+7
| | | | | | It seems that new clang is more picky about asserts for large ints. It not assert-fails when converting large ints to int64. Be more careful when converting these to ints.
* tools/syz-declextract: fix warnings about unused variablesDmitry Vyukov2025-04-101-2/+2
|
* tools/syz-declextract: remove support for old clangDmitry Vyukov2025-04-091-7/+1
|
* tools/syz-declextract/clangtool: fix getBitWidthValue for LLVM>=21Burak Emir2025-04-091-1/+7
|
* tools/syz-declextract: support attributes on typesDmitry Vyukov2025-04-031-1/+9
| | | | | | Remove __attribute__ on types. Some kernels now use it on some syscall args as shown in the test. The __attribute__ may contain quotes and break json.
* tools/syz-declextract: support function scopesDmitry Vyukov2025-01-221-106/+218
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Extract info about function scopes formed by switch'es on function arguments. For example if we have: void foo(..., int cmd, ...) { ... switch (cmd) { case FOO: ... block 1 ... case BAR: ... block 2 ... } ... } We record that any data flow within block 1 is only relevant when foo's arg cmd has value FOO, similarly for block 2 and BAR. This allows to do 3 things: 1. Locate ioctl commands that are switched on within transitively called functions. 2. Infer return value for each ioctl command. 3. Infer argument type when it's not specified in _IO macro. This will also allow to infer other multiplexed syscalls. Descriptions generated on Linux commit c4b9570cfb63501.
* tools/syz-declextract: fix empty structs and arraysDmitry Vyukov2025-01-201-3/+10
| | | | | | | | | | | | | | | | This fixes 2 bugs: 1. We completly remove empty structs, but they can have effect on parent struct layout if they have >1 alignment. Replace empty structs with a special auto_aligner type that preserves alignment. 2. Arrays of 0 size are currently emitted as dynamically-sized (we assume 0 size means "this is not a const-size array"). Add separate IsConstSize flag for arrays that marks const-size arrays. Additionally cross-check that generated structs have exactly the same size/alignment as the corresponding C structs. This allows to catch the above bugs.
* pkg/declextract: move const handling logic from the clang toolDmitry Vyukov2025-01-171-18/+10
| | | | | | | | Export raw info about consts from the clang tool, and let the Go part handle it. The less logic is in the clang tool, the better. Also this will allow to remove unused includes when we know which consts we ended up using. The more includes we include, the higher the chances we include something that's broken.
* tools/syz-declextract: infer argument/field typesDmitry Vyukov2024-12-171-20/+169
| | | | | | Use data flow analysis to infer syscall argument, return value, and struct field types. See the comment in pkg/declextract/typing.go for more details.
* tools/syz-declextract: extract info about all functionsDmitry Vyukov2024-12-131-0/+37
| | | | | | Extract info about all functions, and compute total LOC for each interface. For now only static calls are considered, this doesn't handle indirect calls yet. This is just a groundwork for more complex callgraph/dataflow analysis.
* tools/syz-declextract: extract file_operations descriptionsDmitry Vyukov2024-12-111-2/+132
| | | | | | | | Extend the clang tool to locate file_operations variables and arrays and dump open/read/write/mmap/ioctl callbacks for each. It also tries to extract set of ioctl commands and argument types for them in a simple best-effort way (for now). It just locates switch in the ioctl callback and extracts each case as a command.
* pkg/declextract: rename generated names for consistencyDmitry Vyukov2024-12-111-4/+1
| | | | | | Currently we append "$auto", or "$auto_record", or prepend "auto_", or insert "auto" somewhere in the middle. Use more consistent naming: always append "$auto".
* tools/syz-declextract: rewriteDmitry Vyukov2024-12-111-0/+545
syz-declextract accumulated a bunch of code health problems so that now it's hard to change/extend it, lots of new features can only be added in in hacky ways and cause lots of code duplication. It's also completly untested. Rewrite the tool to: - move as much code as possible to Go (working with the clang tool is painful for a number of reasons) - allow testing and add unit tests (first layer of tests test what information is produced by the clang tool, second layer of tests test how that information is transformed to descriptions) - allow extending the clang tool output to export arbitrary info in non-hacky way (now it produces arbitrary JSON instead of a mix of incomplete descriptions and interfaces) - remove code duplication in the clang tool and provide common infrastructure to add new analysis w/o causing more duplication - provide more convinient primitives in the clang tool - improve code style consistency and stick to the LLVM code style (in particular, variable names must start with a capital letter, single-statement blocks are not surrounded with {}) - remove intermixing of code that works on different levels (currently we have AST analysis + busness logic + printfs all intermixed with each other) - provide several helper Go packages for better code structuring (e.g. pkg/clangtool just runs the tool on source files in parallel and returns results, this already separates a bunch of low-level logic from the rest of the code under a simple abstraction) I've tried to make the output match the current output as much as possible so that the diff is managable (in some cases at the cost of code quality, this should be fixed in future commits). There are still some differences, but hopefully they are managable for review (more includes/defines, reordered some netlink attributes). Fixed minor bugs are fixed along the way, but mostly NFC: 1. Some unions were incorrectly emitted as [varlen] (C unions are never varlen). 2. Only a of [packed], [align[N]] attributes was emitted for struct (both couldn't be emitted).