Update: Resolution
Reduced the scope of strerror_r use to the Apple platform where strerror_l is not yet available and deliberately opted to discard the return value to avoid dealing with complicated XSI-compliance detection. Prefer strerror_l otherwise on Unix-like platforms as to-be-recommended by POSIX spec. See the PR description for more detail.
Summary
A user in mongodb/mongo-php-driver#1445 reported a build error compiling libbson (via the PHP driver) on Alpine Linux:
/tmp/t/php-src/ext/mongodb/src/libmongoc/src/libbson/src/bson/bson-error.c:113:8: error: incompatible integer to pointer conversion assigning to 'char *' from 'int' [-Wint-conversion] ret = strerror_r (err_code, buf, buflen); ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 error generated.
According to the clang docs, -Wint-conversion is an error by default. Since libbson is tested with clang, I think this has more to do with Alpine linux. Some further research lead me to strerror_r(3):
The XSI-compliant version of strerror_r() is provided if:
(_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCEOtherwise, the GNU-specific version is provided.
Looking at bson-error.c, libbson currently uses the following condition to check for GNU:
defined(__GNUC__) && defined(_GNU_SOURCE)
If that condition is not met, XSI is used by default.
Environment
User was compiling the PHP driver 1.16.1 with bundled libbson 1.24.1 using clang on Alpine Linux (versions unknown).
The PHP driver was being compiled statically into PHP, which is atypical, but I don't think that's relevant.
Additional Background
Some related discussions on strerror_r(3) and Alpine:
- is depended on by
-
PHPC-2263 Detect XSI or GNU strerror_r() implementation during build process
- Closed
- related to
-
PHPC-2332 Fix bson_strerror_r compatibility for AIX
- Closed
-
CDRIVER-4790 AIX has a glibc-compatible strerror_r w/ diff name
- Closed
-
PHPC-2270 Define constants for POSIX features and extensions used by libmongoc 1.24
- Closed
- links to