Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1559528

Re: llist code relies on undefined behaviour, upsets llvm/clang

From Peter Zijlstra <peterz@infradead.org>
Newsgroups linux.kernel
Subject Re: llist code relies on undefined behaviour, upsets llvm/clang
Date 2017-01-16 10:10 +0100
Message-ID <t0bsB-6yd-23@gated-at.bofh.it> (permalink)
References <t00GS-7DV-23@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Mon, Jan 16, 2017 at 08:36:00AM +1100, Anton Blanchard wrote:
> Hi,
> 
> I was debugging a hang on a ppc64le kernel built with clang, and it
> looks to be undefined behaviour with pointer wrapping in the llist code.
> 
> A test case is below. llist_for_each_entry() does container_of() on a
> NULL pointer, which wraps our pointer negative, then adds the same
> offset back in and expects to get back to NULL. Unfortunately clang
> decides that this can never be NULL and optimises it into an infinite
> loop.
> 
> Build with -DFIX, such that the llist_node has a zero offset from the
> start of the struct, and things work.
> 
> Is anyone other than ppc64le building kernels with llvm/clang these
> days? This should reproduce on ARM64 and x86-64.

Last I checked I couldn't build a x86_64 kernel with llvm. So no, not
something I've ever ran into.


Also, I would argue that this is broken in llvm, the kernel very much
relies on things like this all over the place. Sure, we're way outside
of what the C language spec says, but who bloody cares ;-)

If llvm wants to compile the kernel, it needs to learn the C dialect the
kernel uses.

Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

llist code relies on undefined behaviour, upsets llvm/clang Anton Blanchard <anton@samba.org> - 2017-01-15 22:40 +0100
  Re: llist code relies on undefined behaviour, upsets llvm/clang Peter Zijlstra <peterz@infradead.org> - 2017-01-16 10:10 +0100
    Re: llist code relies on undefined behaviour, upsets llvm/clang Anton Blanchard <anton@samba.org> - 2017-01-16 12:50 +0100
      Re: llist code relies on undefined behaviour, upsets llvm/clang Peter Zijlstra <peterz@infradead.org> - 2017-01-16 14:00 +0100
        Re: llist code relies on undefined behaviour, upsets llvm/clang Andrey Ryabinin <ryabinin.a.a@gmail.com> - 2017-01-16 14:10 +0100
  RE: llist code relies on undefined behaviour, upsets llvm/clang David Laight <David.Laight@ACULAB.COM> - 2017-01-16 15:40 +0100
    Re: llist code relies on undefined behaviour, upsets llvm/clang Peter Zijlstra <peterz@infradead.org> - 2017-01-16 17:30 +0100

csiph-web