Darwin's libpthread creates threads with only 512KB of stack space, as opposed to the main thread's 8MB. 512KB often isn't enough to compile properly, so we get stack overflows during ThinLTO.
Unfortunately, with Posix threads the stack size can only be set during creation so there's no way to use the real std::thread to overcome this limit (even with the native handle).
So this patch adds a real implementation of llvm::thread (with the same interface as std::thread) when compiling for Apple that does request the full 8MB stack size. Most of the implementation is cribbed from libc++, with abstractions removed because we know the underlying implementation and target standard (and because we can tell users not to be daft and #define Thread 0).
clang-tidy: warning: #includes are not sorted properly [llvm-include-order]
not useful
clang-format: please reformat the code