When executing test-suite tests with -static option, we get stdthreadbug test to fail.
Sometimes it segfault, sometimes it gets stuck in an infinite loop.
The reason for such behavior is that pthread library uses weak symbols for some functions
(ex. __pthread_mutex_lock), and such functions are not included in the executable when
-static option is used. To force the linker to include these functions as well, we use the following
options: -Wl,--whole-archive -lpthread -Wl,--no-whole-archive.
I proposed adding this options to the test-suite for the stdthreadbug test here D52878,
and got a recommendation to try to teach the clang to handle this case by always including
given options when -pthread is used.
This patch does exactly that.
My concern about this is that we are forcing whole pthread into an executable, and user
does not have an option do decide if he wants to use lpthread or something else. Now,
I am not sure what exactly that something else could be, and maybe there isn't something else
and my concerns aren't justified.