Description
Describe the bug
"CFLAGS="-O3" meson setup --buildtype=plain"
can produce more optimized binaries than meson setup --buildtype=release
because the first passes -O3
to the link stage, while the second does not, which at least with gcc, enables some optimizations at linking time.
(I originally noticed this when using diffoscope to compare an autoconf-to-meson conversion, when I was comparing the output of autoconf with CFLAGS="-O3"
to meson with --buildtype=release
. I fixed that by switching the meson build to "CFLAGS="-O3" meson setup --buildtype=plain"
for a better comparison.)
To Reproduce
- Download https://www.x.org/releases/individual/lib/libXau-1.0.12.tar.gz on a Linux or Unix-like system with gcc installed
meson setup --buildtype=release release ; meson compile -C release -v
CFLAGS="-O3" meson setup --buildtype=plain plain ; meson compile -C plain -v
- compare
release/libXau.so.6.0.0
toplain/libXau.so.6.0.0
In the plain version, I see a smaller .gnu.hash
section in the plain compile than in the release compile. When looking at the output flags passed to gcc at the linking step, I see only the plain compile passed -O3
to the linking step. (This is a small simple library, but enough to show differences; a larger, more complex library would presumably show more differences.)
Expected behavior
I expected --buildtype=release
to not skip the simple link time optimizations normally included by gcc -O3
system parameters
- I saw this first in the freedesktop.org gitlab CI environment, using
- Arch Linux on x64
core/python 3.13.1-1
core/gcc 14.2.1+r753+g1cd744a6828f-1
extra/meson 1.7.0-1
extra/ninja 1.12.1-2
- I reproduced in a VM locally, using
- Oracle Linux 9 on x64
python3-3.9.21-1.el9_5.x86_64
gcc-11.5.0-2.0.1.el9.x86_64
meson-0.58.2-1.el9.noarch
ninja-build-1.10.2-6.el9.x86_64