crashappsec / libcon4m

Base Compiler and Runtime Support for con4m
Apache License 2.0
0 stars 0 forks source link

meson: `-flto` should be passed to both compiler and linker, or neither #61

Closed ee7 closed 2 weeks ago

ee7 commented 2 weeks ago

Low priority ticket.

It looks like the intention is to enable LTO, because we pass -flto to the linker:

https://github.com/crashappsec/libcon4m/blob/14604adf6ca68c75a08360129d71beb63571c1d1/meson.build#L41

However, I believe this doesn't properly enable LTO anywhere, because we don't pass the flag the compiler. And from the GCC manual:

To use the link-time optimizer, -flto and optimization options should be specified at compile time and during the final link. It is recommended that you compile all the files participating in the same link with the same options and also specify those options at link time.

I'd suggest we either remove the flag, or pass it to the compiler too, or use Meson's b_lto.

Aside: the inverse situation, passing -flto to only the compiler, generally works:

GCC automatically performs link-time optimization if any of the objects involved were compiled with the -flto command-line option.