Skip to content

Commit 08ab786

Browse files
Shinyzenithojeda
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 <aakashsensharma@gmail.com> Closes: #1013 Tested-by: Ariel Miculas <amiculas@cisco.com> Reviewed-by: Gary Guo <gary@garyguo.net> Link: https://lore.kernel.org/r/20230612194311.24826-1-aakashsensharma@gmail.com [ 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 <ojeda@kernel.org>
1 parent 9418e68 commit 08ab786

File tree

6 files changed

+13
-17
lines changed

6 files changed

+13
-17
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.71.1 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

Documentation/rust/quick-start.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ the ``bindgen`` tool. A particular version is required.
9898

9999
Install it via (note that this will download and build the tool from source)::
100100

101-
cargo install --locked --version $(scripts/min-tool-version.sh bindgen) bindgen
101+
cargo install --locked --version $(scripts/min-tool-version.sh bindgen) bindgen-cli
102102

103103
``bindgen`` needs to find a suitable ``libclang`` in order to work. If it is
104104
not found (or a different ``libclang`` than the one found should be used),

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
@@ -138,19 +138,18 @@ void rust_helper_put_task_struct(struct task_struct *t)
138138
EXPORT_SYMBOL_GPL(rust_helper_put_task_struct);
139139

140140
/*
141-
* We use `bindgen`'s `--size_t-is-usize` option to bind the C `size_t` type
142-
* as the Rust `usize` type, so we can use it in contexts where Rust
143-
* expects a `usize` like slice (array) indices. `usize` is defined to be
144-
* the same as C's `uintptr_t` type (can hold any pointer) but not
145-
* necessarily the same as `size_t` (can hold the size of any single
146-
* object). Most modern platforms use the same concrete integer type for
141+
* `bindgen` binds the C `size_t` type as the Rust `usize` type, so we can
142+
* use it in contexts where Rust expects a `usize` like slice (array) indices.
143+
* `usize` is defined to be the same as C's `uintptr_t` type (can hold any
144+
* pointer) but not necessarily the same as `size_t` (can hold the size of any
145+
* single object). Most modern platforms use the same concrete integer type for
147146
* both of them, but in case we find ourselves on a platform where
148147
* that's not true, fail early instead of risking ABI or
149148
* integer-overflow issues.
150149
*
151150
* If your platform fails this assertion, it means that you are in
152-
* danger of integer-overflow bugs (even if you attempt to remove
153-
* `--size_t-is-usize`). It may be easiest to change the kernel ABI on
151+
* danger of integer-overflow bugs (even if you attempt to add
152+
* `--no-size_t-is-usize`). It may be easiest to change the kernel ABI on
154153
* your platform such that `size_t` matches `uintptr_t` (i.e., to increase
155154
* `size_t`, because `uintptr_t` has to be at least as big as `size_t`).
156155
*/

rust/kernel/lib.rs

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

scripts/min-tool-version.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ rustc)
3434
echo 1.71.1
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)