Re: Do we use -fno-omit-frame-pointers by accident?

Dimitry Andric <[email protected]> Fri, 19 Jun 2026 18:29:46 +0200
Newsgroups gmane.os.freebsd.devel.hackers
Message-ID <[email protected]>
On 19 Jun 2026, at 17:24, Martin Cracauer <[email protected]> wrote:
> 
> Martin Cracauer wrote on Thu, Jun 18, 2026 at 04:51:41PM -0400: 
>> I was about to propose on BSDCan to turn on -fno-omit-frame-pointer
>> for the base system userland and most ports.[*]
>> 
>> So I went benchmarking the performance impact.
>> 
>> I discovered that CFLAGS+=-fno-omit-frame-pointer changes nothing
>> about our binaries and shared libraries.  CFLAGS+=-fomit-frame-pointer
>> makes them a little smaller.  So it looks like we default to having
>> frame pointers... somehow.  I verified in the compiler stdout that the
>> flags I set are in fact in effect.
>> 
>> Sizes for 16-current 283959bbe0863917c4fc3200a92d1055a4c89bdc /bin/sh:
>> 
>>   text    data     bss     dec     hex filename
>> - default: 
>> 164503    3712    5520  173735   2a6a7
>> - -fomit-frame-pointer
>> 163831    3712    6192  173735   2a6a7
>> - -fno-omit-frame-pointer
>> 164503    3712    5520  173735   2a6a7
> 
> Performance measurements confirm.  Userland (including llvm) compiled
> with -fomit-frame-pointer is 2% faster for `make buildworld
> buildkernel`.  2% is generally assumed to be the average slowdown from
> frame pointers.
> 
> -fomit-frame-pointer:
> 45:50.00 2750.00 real 60147.28 user 1657.93 sys 2247% CPU
> default freebsd:
> 46:29.94 2789.94 real 61529.67 user 1629.37 sys 2263% CPU
> 
> I conclude that we indeed include frame pointers for userland, but I
> can't see where we turn that on.

It's due to useFramePointerForTargetByDefault() in contrib/llvm-project/clang/lib/Driver/ToolChains/CommonArgs.cpp, which does have a special case for NetBSD:

  if (Triple.isOSFuchsia() || Triple.isOSNetBSD()) {
    return !clang::driver::tools::areOptimizationsEnabled(Args);
  }

but not for FreeBSD. The default return value is true.

We could consider adding "|| Triple.isOSFreeBSD()" to the above if statement, which would mean that enabling any optimizations would get rid of the frame pointer. But it's very annoying for debugging and profiling.

I guess it would be better to have some sort of option for bsd.sys.mk to enable or disable frame pointers on demand, and explicitly pass the required options to the compiler.

-Dimitry