This is the first in a series of patches to port libc++ to Solaris. There does exist a
slightly bitrotten port, however it was done on Illumos (an OpenSolaris derivative)
and the two have diverged in some areas over the last 10 years.
Building libc++ on Solaris fails like this:
In file included from /vol/llvm/src/llvm-project/local/libcxx/include/atomic:550, from /vol/llvm/src/llvm-project/local/libcxx/include/memory:681, from /vol/llvm/src/llvm-project/local/libcxx/include/algorithm:643, from /vol/llvm/src/llvm-project/local/libcxx/test/libcxx/double_include.sh.cpp:24: /vol/llvm/src/llvm-project/local/libcxx/include/semaphore:165:73: error: ‘SEM_VALUE_MAX’ was not declared in this scope 165 | typename conditional<(__least_max_value > 1 && __least_max_value <= _LIBCPP_SEMAPHORE_MAX), | ^~~~~~~~~~~~~~~~~~~~~
This happens because <limits.h> doesn't define SEM_VALUE_MAX. While this is
allowed by XPG7 if the value is indeterminate ([[ https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/limits.h.html#tag_13_24 | XPG7 <limits.h> ]] and the
application is expected to fall back to sysconf(_SC_SEM_VALUE_MAX), this isn't the case on Solaris:
sysconf(_SC_SEM_VALUE_MAX) always returns _SEM_VALUE_MAX from
<sys/param.h>.
I've chose a solution similar to the one in Python Issue 3110 which uses that value as a fallback.
Tested on amd64-pc-solaris2.11 (Solaris 11.4, 11.3 and OpenIndiana 2020.04).
Ok for master?