https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90229
Bug ID: 90229 Summary: Interaction among -Wl,--as-needed and LTO results in an undefined symbol Product: gcc Version: 9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: lto Assignee: unassigned at gcc dot gnu.org Reporter: marxin at gcc dot gnu.org CC: marxin at gcc dot gnu.org Target Milestone: --- As seen in few openSUSE packages with LTO enabled: https://bugzilla.opensuse.org/show_bug.cgi?id=1133232 https://bugzilla.opensuse.org/show_bug.cgi?id=1133131 There's some issue: $ cat lib.cc int FLAGS_verbose; $ g++ -shared -fPIC lib.cc -o mylib.so $ g++ -pthread 1.ii libpes.so -Wl,--as-needed -O [OK] But: $ g++ -pthread 1.ii libpes.so -Wl,--as-needed -O -flto /usr/lib64/gcc/x86_64-suse-linux/8/../../../../x86_64-suse-linux/bin/ld: /usr/lib64/gcc/x86_64-suse-linux/8/libstdc++.so: undefined reference to `pthread_create' collect2: error: ld returned 1 exit status