-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
--buildtype=release doesn't pass optimizer flag to linker #14236
Comments
It's an interesting thought. The binutils linker documents that level is insignificant, -O1 is equivalent to -O3, and also that it currently does nothing for executables, only shared libraries. It makes sense to pass it along, I suppose. Certainly, we don't seem to document -D optimization=3 as being "compiler optimizations" but not "linker optimizations", so it is fair game to change this. |
bfd documents:
lld documents:
I don't have access to other linkers to check. I'll note that
|
But wait. Is Alan talking about |
An explicit reproducer case was provided which involves configuring libXau using
No LTO mentioned. I haven't checked but I doubt the project is forcing b_lto=true in default_options. |
The reason I ask is that I wasn't aware that GCC ever passed down |
I can't reproduce a difference, anyway. Actually I just realized that we use get_optimization_link_args() and pass -Wl,-O1 to the link stage, so the thing I suggested maybe we should do, it turns out we are in fact doing it. |
Describe the bug
"CFLAGS="-O3" meson setup --buildtype=plain"
can produce more optimized binaries thanmeson 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
meson setup --buildtype=release release ; meson compile -C release -v
CFLAGS="-O3" meson setup --buildtype=plain plain ; meson compile -C plain -v
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 bygcc -O3
system parameters
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
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
The text was updated successfully, but these errors were encountered: