https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80407
Bug ID: 80407 Summary: --as-needed cannot be combined with -flto Product: gcc Version: 6.3.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: lto Assignee: unassigned at gcc dot gnu.org Reporter: dilyan.palauzov at aegee dot org Target Milestone: --- Created attachment 41185 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=41185&action=edit Sample With the attached package I do ./configure and make clean && make LDFLAGS="-Wl,--as-needed" && ./m -- works, prints x make clean && CFLAGS="-flto" make && ./m -- works, prints x make clean && make CFLAGS="-flto" LDFLAGS="-Wl,--as-needed" && ./m -- does not work, prints x-0.libs/lt-m: symbol lookup error: x-0/.libs/libx.so.0: undefined symbol: x Why doesn't --as-needed work with LTO? It happens when I use GNU ld (GNU Binutils) 2.28.51.20170411 with either GCC 7.0.1 20170411 or GCC 6.3.1 20170329.