Skip to content

Commit f1673e8

Browse files
Shinyzenithcthbleachbit
authored andcommitted
rust: bindgen: upgrade to 0.65.1
In LLVM 16, anonymous items may return names like `(unnamed union at ..)` rather than empty names [1], which breaks Rust-enabled builds because bindgen assumed an empty name instead of detecting them via `clang_Cursor_isAnonymous` [2]: $ 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 ... This was fixed in bindgen 0.62.0. Therefore, upgrade bindgen to a more recent version, 0.65.1, to support LLVM 16. Since bindgen 0.58.0 changed the `--{white,black}list-*` flags to `--{allow,block}list-*` [3], update them on our side too. In addition, bindgen 0.61.0 moved its CLI utility into a binary crate called `bindgen-cli` [4]. Thus update the installation command in the Quick Start guide. Moreover, bindgen 0.61.0 changed the default functionality to bind `size_t` to `usize` [5] and added the `--no-size_t-is-usize` flag to not bind `size_t` as `usize`. Then bindgen 0.65.0 removed the `--size_t-is-usize` flag [6]. Thus stop passing the flag to bindgen. Finally, bindgen 0.61.0 added support for the `noreturn` attribute (in its different forms) [7]. Thus remove the infinite loop in our Rust panic handler after calling `BUG()`, since bindgen now correctly generates a `BUG()` binding that returns `!` instead of `()`. 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#2284 [4] Link: rust-lang/rust-bindgen@cc78b6f [5] Link: rust-lang/rust-bindgen#2408 [6] Link: rust-lang/rust-bindgen#2094 [7] Signed-off-by: Aakash Sen Sharma <[email protected]> Closes: Rust-for-Linux#1013 Tested-by: Ariel Miculas <[email protected]> Reviewed-by: Gary Guo <[email protected]> Link: https://lore.kernel.org/r/[email protected] [ Reworded commit message. Mentioned the `bindgen-cli` binary crate change, linked to it and updated the Quick Start guide. Re-added a deleted "as" word in a code comment and reflowed comment to respect the maximum length. ] Signed-off-by: Miguel Ojeda <[email protected]>
1 parent 4ce7122 commit f1673e8

File tree

4 files changed

+11
-15
lines changed

4 files changed

+11
-15
lines changed

rust/Makefile

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

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

rust/helpers.c

+7-8
Original file line numberDiff line numberDiff line change
@@ -129,19 +129,18 @@ void rust_helper_put_task_struct(struct task_struct *t)
129129
EXPORT_SYMBOL_GPL(rust_helper_put_task_struct);
130130

131131
/*
132-
* We use `bindgen`'s `--size_t-is-usize` option to bind the C `size_t` type
133-
* as the Rust `usize` type, so we can use it in contexts where Rust
134-
* expects a `usize` like slice (array) indices. `usize` is defined to be
135-
* the same as C's `uintptr_t` type (can hold any pointer) but not
136-
* necessarily the same as `size_t` (can hold the size of any single
137-
* object). Most modern platforms use the same concrete integer type for
132+
* `bindgen` binds the C `size_t` type as the Rust `usize` type, so we can
133+
* use it in contexts where Rust expects a `usize` like slice (array) indices.
134+
* `usize` is defined to be the same as C's `uintptr_t` type (can hold any
135+
* pointer) but not necessarily the same as `size_t` (can hold the size of any
136+
* single object). Most modern platforms use the same concrete integer type for
138137
* both of them, but in case we find ourselves on a platform where
139138
* that's not true, fail early instead of risking ABI or
140139
* integer-overflow issues.
141140
*
142141
* If your platform fails this assertion, it means that you are in
143-
* danger of integer-overflow bugs (even if you attempt to remove
144-
* `--size_t-is-usize`). It may be easiest to change the kernel ABI on
142+
* danger of integer-overflow bugs (even if you attempt to add
143+
* `--no-size_t-is-usize`). It may be easiest to change the kernel ABI on
145144
* your platform such that `size_t` matches `uintptr_t` (i.e., to increase
146145
* `size_t`, because `uintptr_t` has to be at least as big as `size_t`).
147146
*/

rust/kernel/lib.rs

-3
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,4 @@ fn panic(info: &core::panic::PanicInfo<'_>) -> ! {
9797
pr_emerg!("{}\n", info);
9898
// SAFETY: FFI call.
9999
unsafe { bindings::BUG() };
100-
// Bindgen currently does not recognize `__noreturn` so `BUG` returns `()`
101-
// instead of `!`. See <https://github.com/rust-lang/rust-bindgen/issues/2094>.
102-
loop {}
103100
}

scripts/min-tool-version.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ rustc)
3030
echo 1.62.0
3131
;;
3232
bindgen)
33-
echo 0.56.0
33+
echo 0.65.1
3434
;;
3535
*)
3636
echo "$1: unknown tool" >&2

0 commit comments

Comments
 (0)