Index | Thread | Search

From:
Kirill A. Korinsky <kirill@korins.ky>
Subject:
Re: gcc15: drop -fno-delete-null-pointer-checks local change
To:
Theo Buehler <tb@theobuehler.org>, ports@openbsd.org
Date:
Tue, 18 Nov 2025 11:24:31 +0100

Download raw body.

Thread
On Tue, 18 Nov 2025 11:01:12 +0100,
Claudio Jeker <cjeker@diehard.n-r-g.com> wrote:
> 
> On Tue, Nov 18, 2025 at 10:38:58AM +0100, Theo Buehler wrote:
> > On Mon, Nov 17, 2025 at 02:14:03PM +0100, Claudio Jeker wrote:
> > > In gcc -fdelete-null-pointer-checks is a nightmare.
> > > 
> > > It is a stupid optimisation which has some bad security track record since
> > > it tends to remove 'if (p == NULL) error out' checks. Now on OpenBSD you can
> > > not map the page at address 0 so it is less of a concern since in that
> > > case the code should crash before the check (at least that is the theory).
> > > 
> > > The problem with skipping this optimisation is that a lot of c++ code
> > > breaks because of static asserts against nullptr.
> > > Many of those expressions are actually not using proper const expressions
> > > and so gcc errors out. With -fdelete-null-pointer-checks these checks
> > > get optimised away (because the compiler decided that somewhen before the
> > > static assert the pointer was already dereferenced and so impossible to be
> > > NULL).
> > > 
> > > I got tired to figure out how to pass -fdelete-null-pointer-checks to all
> > > those c++ monsters. The common linux distros all ship with a gcc that has
> > > -fdelete-null-pointer-checks set by default and so we just inflict a lot
> > > of pain on us for being a special snowflake.
> > 
> > I'm not going to object, but as I said elsewhere I would prefer to know
> > what ports are really affected by this. With the exception of ruby/3.3,
> > I think all known cases are already broken on sparc64, so this should
> > not be a blocker.
> > 
> > I think the option was disabled in ports because miod disabled it in
> > base 20 years ago. This is pascal's sync commit:
> > https://github.com/openbsd/ports/commit/e7f261aa1558eedd881e29bc5c69734f9e3f23bc
> > and here's miod's original base commit:
> > 
> > commit 66149774b87757613e220f937ebb9c1d56485993
> > Author: miod <miod@openbsd.org>
> > Date:   Tue Nov 2 21:04:50 2004 +0000
> > 
> >     Do not enable -fdelete-null-pointer-checks at -O2 by default on OpenBSD.
> > 
> >     This optimizations is really cool, but it does not work for complex code;
> >     we had to disable it for Perl 5.8 to run correctly, now it turns out it
> >     broke Bind 9 on powerpc, so neuter it for good.
> > 
> >     ok deraadt@ henning@ millert@ others@
> > 
> > Now hopefully things have improved since then...
> > 
> 
> I'm with you, I also dislike how -fdelete-null-pointer-checks breaks code
> but then it seems any modern c++ code breaks if not built with it. It
> almost seems that libstdc++ itself requires it to work. I think this is
> why people have so many issues with asan and other code sanitizers
> since those disable -fdelete-null-pointer-checks.
>

Here a fresh example of adjusting documentation for real behaviour:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101665

From my point if view we should keep to default behaviour here.

-- 
wbr, Kirill