Messages in this thread | | | Date | Tue, 12 Jan 2021 15:06:34 -0700 | From | Nathan Chancellor <> | Subject | Re: [PATCH] ubsan: Implement __ubsan_handle_alignment_assumption |
| |
On Tue, Jan 12, 2021 at 01:53:30PM -0800, Nick Desaulniers wrote: > On Tue, Jan 12, 2021 at 1:37 PM Nathan Chancellor > <natechancellor@gmail.com> wrote: > > > > > if real_ptr is an unsigned long, do we want to use `__ffs(real_ptr) + > > > 1` here rather than ffs which takes an int? It seems the kernel is > > > missing a definition of ffsl. :( > > > > Why the + 1? I think if we use __ffs (which it seems like we should), I > > think that needs to become > > This came up recently in an internal code review; ffs and __ffs differ > in output by one. See also the definition of ffs for alpha in > arch/alpha/include/asm/bitops.h.
Interesting, thanks for bringing it up! Looks like ffs returns 1-32 and __ffs returns 0-31. I think that we want __ffs here because we are shifting (1UL << 32 overflows on 32-bit architectures) and the code in LLVM appears to agree. LeastSignificantSetBitIndex evaluates to __builtin_ctzl, which is the asm-generic implementation of __ffs.
Cheers, NAthan
| |