Bug 56240

Summary: -fopenmp and -pthread behave inconsistently with respect to -nostdlib
Product: gcc Reporter: Yury V. Zaytsev <yury>
Component: driverAssignee: Not yet assigned to anyone <unassigned>
Status: UNCONFIRMED ---    
Severity: normal CC: tschwinge
Priority: P3 Keywords: openmp
Version: 4.4.5   
Target Milestone: ---   
See Also: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25460
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed:

Description Yury V. Zaytsev 2013-02-07 12:54:15 UTC
Hello,

As reported in #25460, if gcc is passed -nostdlib and -pthread options, the libraries implied by -pthread are not added. It was decided that this is the correct behavior and hence the bug was closed.

Now, if gcc is passed -nostdlib and -fopenmp, the libraries implied by -fopenmp (and -pthread) are in fact added to the executable. The same test case as in #25460 can be used to verify this (you have to use libtool 2.4.2+, however, because earlier versions were filtering out OpenMP flags).

This behavior seems to be inconsistent to me.

In order to make it consistent, either the decision in #25460 can be reconsidered and gcc can be made to adhere to -pthread even if -nostdlib is specified, or the effect of -fopenmp can be changed in a way that gcc will not add -lgomp and libraries implied by -pthread anymore.

I think that the first option is better, because the current behavior of -fopenmp seems to make total sense to me, and, as a nice side effect, changing the behavior of -pthread to match -fopenmp will "unbreak" libtool linking of C++ programs that use threads.

The reasons why libtool uses -nostdlib / adds stubs directly and whether it should do it or not can be debated, but they are outside the scope of this report.

Thank you for your time,
--Yury.