[libcxx-commits] [PATCH] D81602: [libc++] Provide SEM_VALUE_MAX fallback on Solaris

Rainer Orth via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jun 10 11:07:57 PDT 2020

ro created this revision.
ro added a reviewer: libc++.
ro added a project: libc++.
Herald added subscribers: jfb, fedor.sergeev.
Herald added 1 blocking reviewer(s): libc++.

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 (XPG7 `<limits.h>` <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/limits.h.html#tag_13_24> 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

I've chose a solution similar to the one in Python Issue 3110 <https://bugs.python.org/issue3110> 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?

  rG LLVM Github Monorepo



Index: libcxx/include/__config
--- libcxx/include/__config
+++ libcxx/include/__config
@@ -302,6 +302,13 @@
 #  else
 #    define _LIBCPP_BIG_ENDIAN
 #  endif
+#  ifndef SEM_VALUE_MAX
+     // <limits.h> doesn't define SEM_VALUE_MAX as allowed by XPG7.  However,
+     // sysconf(_SC_SEM_VALUE_MAX) has returned _SEM_VALUE_MAX since Solaris 2.6.
+#    define _KMEMUSER
+#    include <sys/param.h>
+#  endif
 #endif // __sun__
 #if defined(__CloudABI__)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81602.269804.patch
Type: text/x-patch
Size: 565 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20200610/0c75a82b/attachment.bin>

More information about the libcxx-commits mailing list