Skip to content

Commit aaacd6c

Browse files
Shinyzenithherrnst
authored andcommitted
rust: bindgen: upgrade to 0.65.1
* Rationale: Upgrades bindgen to code-generation for anonymous unions, structs, and enums [7] for LLVM-16 based toolchains. The following upgrade also incorporates `noreturn` support from bindgen allowing us to remove useless `loop` calls which was placed as a workaround. * Truncated build logs on using bindgen `v0.56.0` prior to LLVM-16 toolchain: ``` $ make rustdoc LLVM=1 CLIPPY=1 -j$(nproc) RUSTC L rust/core.o BINDGEN rust/bindings/bindings_generated.rs BINDGEN rust/bindings/bindings_helpers_generated.rs BINDGEN rust/uapi/uapi_generated.rs thread 'main' panicked at '"ftrace_branch_data_union_(anonymous_at__/_/include/linux/compiler_types_h_146_2)" is not a valid Ident', .../proc-macro2-1.0.24/src/fallback.rs:693:9 ... thread 'main' panicked at '"ftrace_branch_data_union_(anonymous_at__/_/include/linux/compiler_types_h_146_2)" is not a valid Ident', .../proc-macro2-1.0.24/src/fallback.rs:693:9 ... ``` * LLVM-16 Changes: API changes [1] were introduced such that libclang would emit names like "(unnamed union at compiler_types.h:146:2)" for unnamed unions, structs, and enums whereas it previously returned an empty string. * Bindgen Changes: Bindgen `v0.56.0` on LLVM-16 based toolchains hence was unable to process the anonymous union in `include/linux/compiler_types` `struct ftrace_branch_data` and caused subsequent panics as the new `libclang` API emitted name was not being handled. The following issue was fixed in Bindgen `v0.62.0` [2]. Bindgen `v0.58.0` changed the flags `--whitelist-*` and `--blacklist-*` to `--allowlist-*` and `--blocklist-*` respectively [3]. Bindgen `v0.61.0` added support for `_Noreturn`, `[[noreturn]]`, `__attribute__((noreturn))` [4], hence the empty `loop`s used to circumvent bindgen returning `!` in place of `()` for noreturn attributes have been removed completely. Bindgen `v0.61.0` also changed default functionality to bind `size_t` to `usize` [5] and added the `--no-size_t-is-usize` [5] flag to not bind `size_t` as `usize`. Bindgen `v0.65.0` removed `--size_t-is-usize` flag [6]. Link: llvm/llvm-project@19e984e [1] Link: rust-lang/rust-bindgen#2319 [2] Link: rust-lang/rust-bindgen#1990 [3] Link: rust-lang/rust-bindgen#2094 [4] Link: rust-lang/rust-bindgen@cc78b6f [5] Link: rust-lang/rust-bindgen#2408 [6] Closes: Rust-for-Linux/linux#1013 [7] Signed-off-by: Aakash Sen Sharma <[email protected]> Reviewed-by: Gary Guo <[email protected]> Tested-by: Ariel Miculas <[email protected]> Link: https://lore.kernel.org/r/[email protected] [boqun: resolve conflicts because of Rust version bump] Signed-off-by: Boqun Feng <[email protected]>
1 parent 8c99c25 commit aaacd6c

File tree

5 files changed

+11
-15
lines changed

5 files changed

+11
-15
lines changed

Documentation/process/changes.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ you probably needn't concern yourself with pcmciautils.
3232
GNU C 5.1 gcc --version
3333
Clang/LLVM (optional) 11.0.0 clang --version
3434
Rust (optional) 1.68.2 rustc --version
35-
bindgen (optional) 0.56.0 bindgen --version
35+
bindgen (optional) 0.65.1 bindgen --version
3636
GNU make 3.82 make --version
3737
bash 4.2 bash --version
3838
binutils 2.25 ld -v

rust/Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ quiet_cmd_bindgen = BINDGEN $@
303303
$(BINDGEN) $< $(bindgen_target_flags) \
304304
--use-core --with-derive-default --ctypes-prefix core::ffi --no-layout-tests \
305305
--no-debug '.*' \
306-
--size_t-is-usize -o $@ -- $(bindgen_c_flags_final) -DMODULE \
306+
-o $@ -- $(bindgen_c_flags_final) -DMODULE \
307307
$(bindgen_target_cflags) $(bindgen_target_extra)
308308

309309
$(obj)/bindings/bindings_generated.rs: private bindgen_target_flags = \
@@ -323,8 +323,8 @@ $(obj)/uapi/uapi_generated.rs: $(src)/uapi/uapi_helper.h \
323323
# given it is `libclang`; but for consistency, future Clang changes and/or
324324
# a potential future GCC backend for `bindgen`, we disable it too.
325325
$(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_flags = \
326-
--blacklist-type '.*' --whitelist-var '' \
327-
--whitelist-function 'rust_helper_.*'
326+
--blocklist-type '.*' --allowlist-var '' \
327+
--allowlist-function 'rust_helper_.*'
328328
$(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_cflags = \
329329
-I$(objtree)/$(obj) -Wno-missing-prototypes -Wno-missing-declarations
330330
$(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_extra = ; \

rust/helpers.c

+6-7
Original file line numberDiff line numberDiff line change
@@ -574,19 +574,18 @@ EXPORT_SYMBOL_GPL(rust_helper_drm_gem_shmem_object_mmap);
574574
#endif
575575

576576
/*
577-
* We use `bindgen`'s `--size_t-is-usize` option to bind the C `size_t` type
578-
* as the Rust `usize` type, so we can use it in contexts where Rust
579-
* expects a `usize` like slice (array) indices. `usize` is defined to be
580-
* the same as C's `uintptr_t` type (can hold any pointer) but not
581-
* necessarily the same as `size_t` (can hold the size of any single
577+
* `bindgen` binds the C `size_t` type the Rust `usize` type, so we can
578+
* use it in contexts where Rust expects a `usize` like slice (array) indices.
579+
* `usize` is defined to be the same as C's `uintptr_t` type (can hold any pointer)
580+
* but not necessarily the same as `size_t` (can hold the size of any single
582581
* object). Most modern platforms use the same concrete integer type for
583582
* both of them, but in case we find ourselves on a platform where
584583
* that's not true, fail early instead of risking ABI or
585584
* integer-overflow issues.
586585
*
587586
* If your platform fails this assertion, it means that you are in
588-
* danger of integer-overflow bugs (even if you attempt to remove
589-
* `--size_t-is-usize`). It may be easiest to change the kernel ABI on
587+
* danger of integer-overflow bugs (even if you attempt to add
588+
* `--no-size_t-is-usize`). It may be easiest to change the kernel ABI on
590589
* your platform such that `size_t` matches `uintptr_t` (i.e., to increase
591590
* `size_t`, because `uintptr_t` has to be at least as big as `size_t`).
592591
*/

rust/kernel/lib.rs

-3
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,6 @@ fn panic(info: &core::panic::PanicInfo<'_>) -> ! {
165165
pr_emerg!("{}\n", info);
166166
// SAFETY: FFI call.
167167
unsafe { bindings::BUG() };
168-
// Bindgen currently does not recognize `__noreturn` so `BUG` returns `()`
169-
// instead of `!`. See <https://github.com/rust-lang/rust-bindgen/issues/2094>.
170-
loop {}
171168
}
172169

173170
/// Calculates the offset of a field from the beginning of the struct it belongs to.

scripts/min-tool-version.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ rustc)
3434
echo 1.68.2
3535
;;
3636
bindgen)
37-
echo 0.56.0
37+
echo 0.65.1
3838
;;
3939
*)
4040
echo "$1: unknown tool" >&2

0 commit comments

Comments
 (0)