Open andypost opened 2 years ago
Debug shows that it caused by usage
__sync_lock_test_and_set_1
with constant
According to the GCC documentation, the problem likely is that some architecture only support __sync_lock_test_and_set_1
with reduced functionality, meaning:
[…] the only valid value to store is the immediate constant 1. The *exact value actually stored in `ptr` is implementation defined**.
The RISC-V architecture seems to be one of these architectures. For this reason, my understanding is that portable code should not use __sync_lock_test_and_set_1
with a store value other than the constant 1 (in general code using a different value seems to rely on implementation defined behavior). Unfortunately, the lsapilib.c
file does presently use __sync_lock_test_and_set_1
with other store values in three places:
Since there is no builtin supporting this on the RISC-V architecture, this causes the linking error mentioned in the original post when PHP is compiled with --enable-litespeed
. The three code parts linked above correspond to the three “undefined symbol“ linking errors.
As I see gcc suggests to replace this functions with __atomic
ones but looking at sapi/fpm/fpm/fpm_atomic.h
it has own implementations.
related clang docs https://llvm.org/docs/Atomics.html#libcalls-sync
EDIT related for pgsql https://postgrespro.ru/list/id/CA+hUKGL1m-zJeFvY_yOAJbNUh-aPR5fk_zHM=HuD6KVzYRhCsg@mail.gmail.com
History shows that all this __sync
functions been added in 1e7f1b90e81
The primary maintainer of the litespeed SAPI is George Wang, but apparently he doesn't have a Github account yet.
btw patch works for master/8.2 as well
So it should be replaced with __atomic_store()
Btw grep shows that only sapi/fpm
has check for this build-ins, probably it needs broader fix
php-src$ git grep '__sync_'
ext/opcache/jit/vtune/ittnotify_config.h:359:#define __TBB_machine_fetchadd4(addr, val) __sync_fetch_and_add(addr, val)
sapi/fpm/config.m4:292: AC_MSG_CHECKING([if gcc supports __sync_bool_compare_and_swap])
sapi/fpm/config.m4:295: return (__sync_bool_compare_and_swap(&variable, 1, 2)
sapi/fpm/config.m4:296: && __sync_add_and_fetch(&variable, 1)) ? 1 : 0;
sapi/fpm/config.m4:299: AC_DEFINE(HAVE_BUILTIN_ATOMIC, 1, [Define to 1 if gcc supports __sync_bool_compare_and_swap() a.o.])
sapi/fpm/fpm/fpm_atomic.h:19:#define atomic_cmp_set(a,b,c) __sync_bool_compare_and_swap(a,b,c)
sapi/fpm/fpm/fpm_atomic.h:86:#define atomic_cmp_set(a,b,c) __sync_bool_compare_and_swap(a,b,c)
sapi/litespeed/lsapilib.c:444: __sync_fetch_and_sub(s_busy_workers, 1);
sapi/litespeed/lsapilib.c:1593: __sync_fetch_and_add(s_busy_workers, 1);
sapi/litespeed/lsapilib.c:2921: __sync_lock_release(s_busy_workers);
sapi/litespeed/lsapilib.c:2923: __sync_lock_release(s_accepting_workers);
sapi/litespeed/lsapilib.c:2967: if (__sync_bool_compare_and_swap(&child_status->m_state,
sapi/litespeed/lsapilib.c:2972: __sync_fetch_and_sub(s_busy_workers, 1);
sapi/litespeed/lsapilib.c:2974: else if (__sync_bool_compare_and_swap(&child_status->m_state,
sapi/litespeed/lsapilib.c:2979: __sync_fetch_and_sub(s_accepting_workers, 1);
sapi/litespeed/lsapilib.c:3252: accepting = __sync_add_and_fetch(s_accepting_workers, 0);
sapi/litespeed/lsapilib.c:3321: __sync_add_and_fetch(s_busy_workers, 1);
sapi/litespeed/lsapilib.c:3408: __sync_add_and_fetch(s_busy_workers, 1);
sapi/litespeed/lsapilib.c:3525: accepting = __sync_add_and_fetch(s_accepting_workers, 0);
sapi/litespeed/lsapilib.c:3610: ret = __sync_fetch_and_add(s_busy_workers, 0);
sapi/litespeed/lsapilib.c:3657: __sync_fetch_and_add(s_accepting_workers, 1);
sapi/litespeed/lsapilib.c:3663: __sync_fetch_and_sub(s_accepting_workers, 1);
sapi/litespeed/lsapilib.c:3717: __sync_fetch_and_add(s_busy_workers, 1);
sapi/litespeed/lsapilib.c:4388: return __sync_add_and_fetch(s_global_counter, cnt);
Description
Building with
--enable-litespeed
on risv64 fails withDebug shows that it caused by usage
__sync_lock_test_and_set_1
with constant, see https://gitlab.alpinelinux.org/alpine/aports/-/issues/12775#note_204733__sync_lock_test_and_set
with values other than a immediate constant 1 on the RISC-V architecture (if technically possible).It fails for all supported versions 7.4+ but 8.0+ is priority
PHP Version
PHP 8.0+
Operating System
Alpinelinux