|
|
Log in / Subscribe / Register

Rust and UB

Rust and UB

Posted Aug 14, 2024 21:31 UTC (Wed) by khim (subscriber, #9252)
In reply to: Rust and UB by josh
Parent article: Standards for use of unsafe Rust in the kernel

> The Rust compiler doesn't want to be an adversary.

That's an oversimplification. Rust complier doesn't have any wants or desires.

And any optimizing compiler is an adversary. And the better compiler is at optimizing code that conforms to the rules the more destructive it becomes when it had to deal with something that doesn't conform to these rules. It's just in the nature of the beast.

I think better characterization would be: rust compiler is mighty beast that can do lots of good, but failure to control it turns it into raging destructive force that may destroy everything — that's why it's responsibility of both compiler developers and language users to do their part of work that would keep that mighty and powerful yet crazy beast tamed.

We couldn't make “benign compiler” that lots of “we code for the hardware” folks dream about. But we could keep compiler's destructive tendencies in check if we would act together.


to post comments

Rust and UB

Posted Aug 14, 2024 22:23 UTC (Wed) by deltragon (guest, #159552) [Link] (1 responses)

> > The Rust compiler doesn't want to be an adversary.
>
> That's an oversimplification. Rust complier doesn't have any wants or desires.
>
> And any optimizing compiler is an adversary.

I understood this as "the Rust compiler developers and language designers, as a group, don't want to be adversaries".

Rust and UB

Posted Aug 14, 2024 22:41 UTC (Wed) by khim (subscriber, #9252) [Link]

That's why I said that that's oversimplification, not a mistake.

> I understood this as "the Rust compiler developers and language designers, as a group, don't want to be adversaries".

That's correct interpretation, but it's important to remember that there is an adversary and said adversary is precisely the Rust compiler.

It's just the nature of the beast, we don't know how to build an optimizing compiler that wouldn't try to destroy programs with UB.

The only way to tame it is to never let it find an UB to exploit in your program. And the simplest way to achieve that is to ensure that your program doesn't include any UBs in the first place.

Rust and UB

Posted Aug 15, 2024 8:32 UTC (Thu) by intelfx (subscriber, #130118) [Link]

> > The Rust compiler doesn't want to be an adversary.

> That's an oversimplification. Rust complier doesn't have any wants or desires.

You do realize that you're arguing with a Rust lang-team member, right?


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds