llvm.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Gary Guo <gary@garyguo.net>
To: Alice Ryhl <aliceryhl@google.com>
Cc: "Miguel Ojeda" <miguel.ojeda.sandonis@gmail.com>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Alexandre Courbot" <acourbot@nvidia.com>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"kernel test robot" <lkp@intel.com>,
	llvm@lists.linux.dev, oe-kbuild-all@lists.linux.dev,
	"Huacai Chen" <chenhuacai@kernel.org>,
	"WANG Xuerui" <kernel@xen0n.name>
Subject: Re: [linux-next:master 9676/10599] ld.lld: error: undefined symbol: rust_build_error
Date: Mon, 24 Nov 2025 14:48:10 +0000	[thread overview]
Message-ID: <20251124144810.2fb0e99e.gary@garyguo.net> (raw)
In-Reply-To: <aSQ1VNuGHhFXYE2e@google.com>

On Mon, 24 Nov 2025 10:37:08 +0000
Alice Ryhl <aliceryhl@google.com> wrote:

> On Fri, Nov 21, 2025 at 04:53:26PM +0100, Miguel Ojeda wrote:
> > On Fri, Nov 21, 2025 at 3:44 PM Alice Ryhl <aliceryhl@google.com> wrote:  
> > >
> > > You say that this kind of thing would be a compiler bug, but I don't
> > > think the compiler devs folks would agree with us on that at all. I
> > > mean, sure, it's a bug in the sense that it's a missed optimization, but
> > > it's not a correctness bug.  
> >   
> > > I'm not advocating for adding unsafe blocks to skip bounds checks.
> > >
> > > And, fine, there are probably a few cases where it works reliably and
> > > has no real replacement. Such as the VTABLE_DEFAULT_ERROR check. But I
> > > do not think bounds checks are a place where it's a good idea.  
> > 
> > There may be no guarantees, but it is a similar situation as for C
> > compilers in the kernel.  
> 
> I don't think it is like that at all. We rely on non-guaranteed behavior
> for data races because we have no choice and we had extensive discussion
> about it with the compiler folks who are comfortable with us using that
> particular exception.

This is not about LKMM but that BUILD_BUG_ON also relies on compiler
optimizations and reference undefined symbols if compiler cannot
optimize them out.

`build_assert` is just a nicer Rust way of the same trick.

> 
> > Compilers can of course change behavior and have bugs and so on, and
> > thus avoiding to rely on it as much as possible is a good idea, but I
> > think it is a good idea to get build asserts reliably working as much
> > as possible for certain use cases. In particular, I don't see why
> > simple (local-enough) bounds checks cannot be one of those (it may not
> > be today, but it could).
> > 
> > Of course, the best would be to get the language to a point where it
> > supports this sort of thing natively. But that is a longer road.
> > 
> > And, in some situations, there may be no good alternative (i.e. const
> > eval / generics / macros may be too painful to apply), and thus people
> > may end up adding `unsafe` instead, which isn't great.  
> 
> The difference is that someone adding unsafe to avoid a bounds check
> screams to the reviewers that something sketchy is going on. In
> comparison, drivers calling `Bounded::from_expr(_)` with a non-trivial
> expression looks like entirely normal code even though it might be
> relying on the precise and definitely subject-to-change details of when
> LLVM is choosing to inline various functions.
> 
> If const eval / generics / macros are too painful, then perform a
> runtime bounds check just like everyone who uses Rust outside of the
> kernel is doing.

There're 200+ uses of BUILD_BUG_ON in include/. I see this case being
similar to those usages.

> 
> > In addition, I think upstream probably wants to know about this sort
> > of this, i.e. sometimes the changes may be unintended (i.e. if we see
> > it changing in a new nightly) and they probably like to hear about
> > "obvious" optimizations not being applied, since they are potential
> > easy wins for them (or, rather, avoiding regressions), as Gary
> > mentions. That is also part of the value of building the kernel in
> > compiler CIs etc.  
> 
> I do not at all think it's obvious that upstream would be happy about
> this, considering it comes with the serious trade-off of us relying on
> these optimizations happening.

If the exact use case does not involve a reference, it's exactly same
as BUILD_BUG_ON, so would be a LLVM bug that equally affect
clang-built-linux.

Best,
Gary

  parent reply	other threads:[~2025-11-24 14:48 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-20 16:41 [linux-next:master 9676/10599] ld.lld: error: undefined symbol: rust_build_error kernel test robot
2025-11-21  6:13 ` Alexandre Courbot
2025-11-21  9:08   ` Alice Ryhl
2025-11-21 13:41     ` Alexandre Courbot
2025-11-21 14:10       ` Alice Ryhl
2025-11-21 14:21         ` Miguel Ojeda
2025-11-21 14:30           ` Gary Guo
2025-11-21 14:39             ` Alexandre Courbot
2025-11-21 14:44             ` Alice Ryhl
2025-11-21 15:53               ` Miguel Ojeda
2025-11-24 10:37                 ` Alice Ryhl
2025-11-24 12:09                   ` Alexandre Courbot
2025-11-24 14:48                   ` Gary Guo [this message]
2025-11-21 15:27             ` Alexandre Courbot
2025-11-21 15:30               ` Miguel Ojeda
2025-11-22  2:12                 ` Alexandre Courbot
2025-11-21 14:19       ` Miguel Ojeda

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251124144810.2fb0e99e.gary@garyguo.net \
    --to=gary@garyguo.net \
    --cc=acourbot@nvidia.com \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=chenhuacai@kernel.org \
    --cc=kernel@xen0n.name \
    --cc=lkp@intel.com \
    --cc=llvm@lists.linux.dev \
    --cc=miguel.ojeda.sandonis@gmail.com \
    --cc=oe-kbuild-all@lists.linux.dev \
    --cc=ojeda@kernel.org \
    --cc=tmgross@umich.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).