This is an archive of the discontinued LLVM Phabricator instance.

-no-pthread option for mingw-w64
ClosedPublic

Authored by martell on Jul 9 2015, 2:54 PM.

Details

Reviewers
yaron.keren
rnk
Summary

When compiling mingw-w64 gcc provides us with a -no-pthreads option because it is linked in by default
If we want to build mingw-w64 with clang and not gcc we must not link to pthreads
clang currently fails at building mingw-w64 because it errors out for unknown argument.

The handling of the argument in the driver is superficial atm because we don't link to it by default

Diff Detail

Event Timeline

martell updated this revision to Diff 29397.Jul 9 2015, 2:54 PM
martell retitled this revision from to -no-pthread option for mingw-w64.
martell updated this object.
martell added reviewers: yaron.keren, rnk.
yaron.keren edited edge metadata.Jul 9 2015, 10:07 PM

The issue is that gcc accepts -no-pthread while clang errors on it. We may wish to accept -no-pthread even if it has no tunction just for gcc compatibility.

The driver patch does not make any sense, it will trigger only if -pthread -no-pthread are *both* provided.

What I don't understand, what do you mean by "gcc provides us with -no-pthread"? if oyu build using clang gcc is not used at all, how does it enters the picture? -no-pthread comes from a makefile, or??

The issue is that gcc accepts -no-pthread while clang errors on it. We may wish to accept -no-pthread even if it has no tunction just for gcc compatibility.

Yes that would make sense to me also and this is my use case

The driver patch does not make any sense, it will trigger only if -pthread -no-pthread are *both* provided.

Yes the issue here is mingw.org doesn't have libpthread while mingw-w64 links to it by default
For mingw-w64 we would just have

if (!Args.hasArg(options::OPT_no_pthread))
  CmdArgs.push_back("-lpthread");

What I don't understand, what do you mean by "gcc provides us with -no-pthread"? if oyu build using clang gcc is not used at all, how does it enters the picture? -no-pthread comes from a makefile, or??

It comes from the autotools scripts from within mingw-w64's source code.
It is not an option they would remove from the scripts because mingw-w64 assumes libpthread is linked by default.

Is there a way for us to detect if clang is targetting mingw-w64 or mingw.org?
It seems like we are doing this in the constructor of the driver class.
Could we store this somehow to support both cases?

I see, mingw-w64-v4.0.2\mingw-w64-libraries\winpthreads\Makefile.am indeed passes -no-pthread when building winpthreads since pthreads is not available at that time and it is linked by default. clang does not link by default but errors on -no-pthread. I'll commit this switch to avoid the error but we may ignore it otherwise.

martell updated this revision to Diff 29452.Jul 10 2015, 9:39 AM
martell edited edge metadata.

Updated the diff to reflect this

For reference this is a mingw-w64 bootstrap issue.
It should have c11 threading and should not link to pthreads by default.
If I have time I will work on that from within the mingw-w64 project :)

yaron.keren accepted this revision.Jul 10 2015, 11:42 AM
yaron.keren edited edge metadata.

Committed revision 241929.

This revision is now accepted and ready to land.Jul 10 2015, 11:42 AM
martell closed this revision.Jul 10 2015, 11:44 AM

Thanks yaron :)