Replace the ioctl generation pipeline with bindgen clang_macro_fallback#182
Open
zRedShift wants to merge 3 commits into
Open
Replace the ioctl generation pipeline with bindgen clang_macro_fallback#182zRedShift wants to merge 3 commits into
bindgen clang_macro_fallback#182zRedShift wants to merge 3 commits into
Conversation
Replace the generate.sh + list.c cross-compilation pipeline with bindgen's clang_macro_fallback feature. This eliminates the need for cross-compilers, qemu, and pre-generated ioctl text files. A two-pass approach (with and without fallback) identifies function-like macro results, which are then filtered by name prefix and value range to separate real ioctls from non-ioctl macros (v4l2_fourcc, BLK_TC_ACT, etc.). Object-like constants use plain prefix matching for legacy ioctl families. Fixes x32 and m68k ioctl values that had incorrect struct sizes in the old pipeline. Adds ~200-300 new ioctls per arch, and enables sparc and hexagon which previously had no ioctl support.
db0f4a7 to
46ff54a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace the ioctl generation pipeline with
bindgenclang_macro_fallbackThis removes the old
gen/ioctl/generate.sh+list.cpath and generates ioctl constants directly through bindgen.The old setup depended on cross-compilers, qemu, and a hand-maintained ioctl list. The new one keeps everything in the normal bindgen flow by letting clang evaluate
_IO/_IOR/_IOW/_IOWRmacros during generation.What changed
gen/modules/ioctl.hnow includes the relevant UAPI headers directly.For the ioctl module, bindgen runs twice:
#defineconstantsclang_macro_fallback(), which also evaluates function-like macrosThe difference between those two outputs tells us which constants came from macro expansion. Those results are then filtered so we keep actual ioctls and drop the obvious non-ioctl fallout.
The generated ioctl names are also used as the blocklist for the other modules, replacing the old
generated.txt.For m68k, the ioctl bindgen pass uses a small ABI shim so Clang matches GCC/Linux m68k layout for plain
__u64and__s64, while preserving Linux's explicit__aligned_u64alignment.Output changes
Compared to the currently shipped bindings:
list.csparc,sparc64, andhexagonnow get generated ioctl bindings instead of nonex32gets 180 corrected values because the old pipeline usedx86_64layout assumptionsThere are also four compatibility definitions kept in
gen/include/ioctl-addendum.h:REISERFS_IOC_UNPACKCM_IOCGATRCM_IOSDBGLVLMEYEIOC_SYNCThese came from headers that are no longer present in current kernel UAPI, but they were part of previously shipped bindings because the old generated
ioctl.hhad their values baked in. Keeping them here preserves the existing crate API.Breaking changes
This should be released as
0.13.0.Known breaking changes:
FIEMAP_MAX_OFFSETbecomesi32instead ofu32on 32-bit architectures. The bit pattern is unchanged, but the Rust type changes.SIOCGSTAMP_OLDandSIOCGSTAMPNS_OLDmove fromnettoioctlTIOCGETP,TIOCGLTC,TIOCSETN,TIOCSETP, andTIOCSLTCmove fromgeneraltoioctlStub headers
A few minimal libc stubs were added under
gen/include/for-nostdincgeneration:sys/types.hsys/time.hsys/socket.hstdlib.h,string.h, andsys/ioctl.hValidation
I compared the generated ioctl exports against the currently shipped bindings to catch accidental removals and checked the expected value changes on
x32.For m68k, I built a local C-only
m68k-linux-gnuGCC and validated the ioctl constants with compile-time assertions against Linux v6.17 installed headers. This caught the Clang m68kunsigned long longalignment mismatch; the final shim keeps GCC-compatible plain__u64/__s64layout without breaking explicit__aligned_u64ioctls such asKCOV_REMOTE_ENABLEandPPPIOCGL2TPSTATS.I also regenerated the bindings with system libclang and ran the host Rust checks for the
general/ioctlfeature combinations. A localm68k-unknown-linux-gnu -Zbuild-stdRust target check is currently blocked by a nightly rustc/LLVM crash while compilingcompiler_builtins, before this crate is built.