linux-yocto/rust/helpers
Alice Ryhl 6711f72301 rust: bitops: fix missing _find_* functions on 32-bit ARM
commit 6a069876eb1402478900ee0eb7d7fe276bb1f4e3 upstream.

On 32-bit ARM, you may encounter linker errors such as this one:

	ld.lld: error: undefined symbol: _find_next_zero_bit
	>>> referenced by rust_binder_main.43196037ba7bcee1-cgu.0
	>>>               drivers/android/binder/rust_binder_main.o:(<rust_binder_main::process::Process>::insert_or_update_handle) in archive vmlinux.a
	>>> referenced by rust_binder_main.43196037ba7bcee1-cgu.0
	>>>               drivers/android/binder/rust_binder_main.o:(<rust_binder_main::process::Process>::insert_or_update_handle) in archive vmlinux.a

This error occurs because even though the functions are declared by
include/linux/find.h, the definition is #ifdef'd out on 32-bit ARM. This
is because arch/arm/include/asm/bitops.h contains:

	#define find_first_zero_bit(p,sz)	_find_first_zero_bit_le(p,sz)
	#define find_next_zero_bit(p,sz,off)	_find_next_zero_bit_le(p,sz,off)
	#define find_first_bit(p,sz)		_find_first_bit_le(p,sz)
	#define find_next_bit(p,sz,off)		_find_next_bit_le(p,sz,off)

And the underscore-prefixed function is conditional on #ifndef of the
non-underscore-prefixed name, but the declaration in find.h is *not*
conditional on that #ifndef.

To fix the linker error, we ensure that the symbols in question exist
when compiling Rust code. We do this by defining them in rust/helpers/
whenever the normal definition is #ifndef'd out.

Note that these helpers are somewhat unusual in that they do not have
the rust_helper_ prefix that most helpers have. Adding the rust_helper_
prefix does not compile, as 'bindings::_find_next_zero_bit()' will
result in a call to a symbol called _find_next_zero_bit as defined by
include/linux/find.h rather than a symbol with the rust_helper_ prefix.
This is because when a symbol is present in both include/ and
rust/helpers/, the one from include/ wins under the assumption that the
current configuration is one where that helper is unnecessary. This
heuristic fails for _find_next_zero_bit() because the header file always
declares it even if the symbol does not exist.

The functions still use the __rust_helper annotation. This lets the
wrapper function be inlined into Rust code even if full kernel LTO is
not used once the patch series for that feature lands.

Yury: arches are free to implement they own find_bit() functions. Most
rely on generic implementation, but arm32 and m86k - not; so they require
custom handling. Alice confirmed it fixes the build for both.

Cc: stable@vger.kernel.org
Fixes: 6cf93a9ed3 ("rust: add bindings for bitops.h")
Reported-by: Andreas Hindborg <a.hindborg@kernel.org>
Closes: https://rust-for-linux.zulipchat.com/#narrow/channel/x/topic/x/near/561677301
Tested-by: Andreas Hindborg <a.hindborg@kernel.org>
Reviewed-by: Dirk Behme <dirk.behme@de.bosch.com>
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Signed-off-by: Yury Norov (NVIDIA) <yury.norov@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2026-01-23 11:21:12 +01:00
..
atomic.c rust: Introduce atomic API helpers 2025-09-15 09:38:32 +02:00
auxiliary.c rust: auxiliary: use generic device drvdata accessors 2025-07-09 00:04:33 +02:00
barrier.c rust: sync: Add memory barriers 2025-09-15 09:38:34 +02:00
binder.c rust_binder: add Rust Binder driver 2025-09-19 09:40:46 +02:00
bitmap.c rust: add bindings for bitmap.h 2025-09-22 15:52:44 -04:00
bitops.c rust: bitops: fix missing _find_* functions on 32-bit ARM 2026-01-23 11:21:12 +01:00
blk.c
bug.c rust: Add warn_on macro 2025-07-23 02:05:58 +02:00
build_assert.c
build_bug.c
clk.c
completion.c rust: completion: implement initial abstraction 2025-06-13 23:46:56 +02:00
cpu.c rust: cpu: Add CpuId::current() to retrieve current CPU ID 2025-06-12 10:31:28 +05:30
cpufreq.c
cpumask.c
cred.c
device.c rust: device: add drvdata accessors 2025-07-09 00:04:33 +02:00
dma.c rust: dma: add helpers for architectures without CONFIG_HAS_DMA 2026-01-02 12:57:05 +01:00
drm.c
err.c
fs.c
helpers.c Char/Misc/IIO/Binder changes for 6.18-rc1 2025-10-04 16:26:32 -07:00
io.c rust: io: mem: add a generic iomem abstraction 2025-07-20 19:43:14 +02:00
irq.c rust: irq: add support for non-threaded IRQs and handlers 2025-08-12 20:22:00 +02:00
jump_label.c
kunit.c
maple_tree.c rust: maple_tree: add MapleTree 2025-09-21 14:22:19 -07:00
mm.c
mutex.c
of.c rust: device: implement FwNode::is_of_node() 2025-06-25 18:10:12 +02:00
page.c rust_binder: add Rust Binder driver 2025-09-19 09:40:46 +02:00
pci.c rust: Add several miscellaneous PCI helpers 2025-08-15 20:25:42 +02:00
pid_namespace.c
platform.c rust: platform: use generic device drvdata accessors 2025-07-09 00:04:33 +02:00
poll.c poll: rust: allow poll_table ptrs to be null 2025-07-14 14:12:24 +02:00
processor.c rust: Add cpu_relax() helper 2025-08-21 16:58:07 +02:00
property.c rust: device: Create FwNode abstraction for accessing device properties 2025-06-12 23:56:42 +02:00
rbtree.c
rcu.c
refcount.c rust: implement kernel::sync::Refcount 2025-09-15 09:38:35 +02:00
regulator.c rust: regulator: add devm_enable and devm_enable_optional 2025-09-10 21:02:16 +01:00
scatterlist.c rust: scatterlist: Add abstraction for sg_table 2025-09-04 23:33:50 +02:00
security.c rust_binder: add Rust Binder driver 2025-09-19 09:40:46 +02:00
signal.c
slab.c rust: support large alignments in allocations 2025-09-13 16:54:46 -07:00
spinlock.c
sync.c
task.c rust: task: Add Rust version of might_sleep() 2025-06-24 15:53:50 -07:00
time.c rust: time: Add wrapper for fsleep() function 2025-06-30 13:22:05 +02:00
uaccess.c
usb.c rust: usb: add basic USB abstractions 2025-09-24 13:13:04 +02:00
vmalloc.c rust: support large alignments in allocations 2025-09-13 16:54:46 -07:00
wait.c
workqueue.c
xarray.c