[PATCH V13 5/7] rust: Make __udivdi3() and __umoddi3() panic

David Laight david.laight.linux at gmail.com
Fri Apr 24 21:09:43 AEST 2026


On Fri, 24 Apr 2026 11:43:11 +0200
Link Mauve <linkmauve at linkmauve.fr> wrote:

> On Fri, Apr 24, 2026 at 10:14:25AM +0100, David Laight wrote:
> > On Fri, 24 Apr 2026 11:17:40 +0530
> > "Mukesh Kumar Chaurasiya (IBM)" <mkchauras at gmail.com> wrote:
> >   
> > > From: Link Mauve <linkmauve at linkmauve.fr>
> > > 
> > > The core crate currently depends on these two functions for i64/u64/
> > > i128/u128/core::time::Duration formatting, but we shouldn’t use that in
> > > the kernel so let’s panic if they are ever called.  
> > 
> > Ugg.
> > Surely you can make it a link-time failure?
> > Or change the underlying code to avoid the divide.  
> 
> This is currently a link-time failure, which means if any of the core
> crate or drm_panic_qr are linked in, the kernel will fail to link.
> 
> And since we rely on core, that means no kernel can be built on PowerPC
> without this patch.
> 
> A possible solution would be to change the core crate to not divide
> u64s, but the last time I tried to do that I couldn’t quite figure out
> how to do formatting without it, maybe I will just open an issue against
> Rust.

If the problematic code is (effectively) printf("%lld", val) there are much
better ways to generate the digit string than repeated 64bit divides.
On particular you can use 'multiply by reciprocal' instead.
For example see the latest (I think it'll be in 7.1-rc) version of
tools/include/nolibc/stdlib.h

	David


More information about the Linuxppc-dev mailing list