InBetweenNames / gentooLTO

A Gentoo Portage configuration for building with -O3, Graphite, and LTO optimizations

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Trailing -O2 in LDFLAGS?

acjones8 opened this issue · comments

Hello everyone,

I've noticed recently that during the compilation phase for many programs, an -O2 gets tacked on the very end of LDFLAGS. Here's an example from media-tv/kodi:

-Wl,-O1 -Wl,--as-needed -O3 -fgraphite-identity -floop-nest-optimize -fdevirtualize-at-ltrans -fipa-pta -fno-semantic-interposition -flto=auto -fuse-linker-plugin -pipe -march=native -mno-rdrnd -O2

My understanding is that ld has a separate -O flag from GCC, but I would think that's the -Wl,-O1 at the very beginning, whereas the -O2 is just hanging out near the end with the other flags, and concerningly after the -O3. Is this expected behavior? I don't have -O2 anywhere in my COMMON_FLAGS or CFLAGS, so I'm not quite sure where it's coming from or what it's doing here...

I've identified the source of the issue - I was setting CXXFLAGS equal to ${CXXFLAGS} ${CFLAGS}, in case there were any C++ specific flags being set, but it turns out that causes -O2 to be used during the linking step for some reason. Setting CXXFLAGS equal to CFLAGS (to just ${CFLAGS} ) causes the -O2 to disappear. I'm not sure whether or not putting the -O2 there was causing any harm, but I don't see how it could be of much benefit, so I'm sticking with this for now.