Skip to content

Conversation

henderkes
Copy link
Collaborator

What does this PR do?

uv needs to explicitly link -lpthread on centos 7 aarch64, fails to pthread_atfork unresolved otherwise. It's a symbols that's in the static library, but not in the shared library

not sure if this fixes it yet, still testing:

scipy/scipy#11323

…fork unresolved otherwise. It's a symbols that's in the static library, but not in the shared library
@henderkes
Copy link
Collaborator Author

henderkes commented Jun 19, 2025

[15:21:02] [I] [EXEC] /app/buildroot/bin/php -n -d "extension_dir=/app/buildroot/modules" -d "extension=uv" --ri "uv"
[15:21:02] [C] Build failed with SPC\exception\RuntimeException: extension uv failed runtime check: php-cli returned 1

Warning: PHP Startup: Unable to load dynamic library 'uv' (tried: /app/buildroot/modules/uv (/app/buildroot/modules/uv: cannot open shared object file: No such file or directory), /app/buildroot/modules/uv.so (/app/buildroot/modules/uv.so: undefined symbol: pthread_atfork)) in Unknown on line 0
Extension 'uv' not present.
[15:21:02] [C] Please check with --debug option to see more details.

it doesn't fix it... that's annoying. I'll debug it further tomorrow

@henderkes henderkes marked this pull request as draft June 19, 2025 15:22
@crazywhalecc
Copy link
Owner

crazywhalecc commented Jun 19, 2025

The bin/spc-gnu-docker I tested locally seems to be able to build shared uv extension and load it normally without any errors.

@henderkes
Copy link
Collaborator Author

henderkes commented Jun 20, 2025

on aarch64? On x86_64 I don't have an issue with it either, only on aarch64. I'm using the full extension set with ZTS

I could imagine it being related to thread safety.

@henderkes
Copy link
Collaborator Author

henderkes commented Jun 20, 2025

I've tried to set up SPC_USE_ARCH=aarch64 to test changes faster but it's failing on yum update after

        sed -i 's|mirror.centos.org/centos|vault.centos.org/altarch|g' /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo ; \
        sed -i 's|mirror.centos.org/centos|vault.centos.org/altarch|g' /etc/yum.repos.d/CentOS-SCLo-scl.repo ; \

Trying to access x86_64 urls instead of aarch64.

@crazywhalecc
Copy link
Owner

Damn firewall, my Linux server can't access docker.com and github.com anymore unless using proxy. I really don't understand why this is blocked.

I also found that the current alpine-docker and gnu-docker do not work correctly on mac with SPC_USE_ARCH, I will dig in and find a reasonable way to emulate this across architectures.

@henderkes
Copy link
Collaborator Author

Damn firewall, my Linux server can't access docker.com and github.com anymore unless using proxy. I really don't understand why this is blocked.

Yeah I'm hitting this so often here in Asia, it never happens in Europe. My connection to many American services is often times extremely slow, like Oracle, AWS, GitHubs downloads (repo is fine, luckily) and so many more.

@henderkes
Copy link
Collaborator Author

henderkes commented Jun 20, 2025

# PHP version to build (default: 8.4)
php-version: 8.2
# [REQUIRED] Static PHP extensions to build (list or comma-separated are both accepted)
extensions: apcu,ast,bcmath,calendar,ctype,curl,dba,dom,exif,fileinfo,filter,iconv,libxml,mbregex,mbstring,opcache,openssl,pcntl,phar,posix,readline,session,simplexml,sockets,sodium,tokenizer,xml,xmlreader,xmlwriter,zip,zlib
# [OPTIONAL] Shared PHP extensions to build (list or comma-separated are both accepted)
shared-extensions: [amqp,brotli,bz2,dio,ds,ev,event,ffi,ftp,gd,gettext,gmp,gmssl,igbinary,imagick,inotify,intl,ldap,lz4,memcache,memcached,mongodb,msgpack,mysqli,mysqlnd,odbc,opentelemetry,parallel,pdo,pdo_mysql,pdo_odbc,pdo_pgsql,pdo_sqlite,pdo_sqlsrv,pgsql,protobuf,rar,redis,rdkafka,shmop,spx,sqlite3,sqlsrv,ssh2,swoole,sysvmsg,sysvsem,sysvshm,tidy,uuid,uv,xdebug,xhprof,xlswriter,xsl,xz,yac,yaml,zstd]
# Extra libraries to build (list or comma-separated are both accepted)
libs: [libacl, libavif, nghttp3, ngtcp2, watcher]
# [REQUIRED] Build SAPIs (list or comma-separated are both accepted)
sapi: cli,embed,fpm,frankenphp
# Show full console output (default: false)
debug: false
# Build options (same as `build` command options, all options are optional)
build-options:
    # Build with Zend Thread Safety (ZTS) enabled (default: false)
    enable-zts: true
    # Before build, remove all old build files and sources (default: false)
    with-clean: false
    # Build with all suggested libraries (default: false)
    with-suggested-libs: true
    # Build with all suggested extensions (default: false)
    with-suggested-exts: false
    # Build without stripping the binary (default: false)
    no-strip: false
    # Disable Opcache JIT (default: false)
    disable-opcache-jit: false
    # PHP configuration options (same as --with-config-file-path)
    with-config-file-path: "/etc/php-zts.ini"
    # PHP configuration options (same as --with-config-file-scan-dir)
    with-config-file-scan-dir: "/etc/php-zts.d"
    # Hardcoded INI options for cli and micro SAPI (e.g. "memory_limit=4G", list accepted)
    with-hardcoded-ini: [ ]
    # Pretend micro SAPI as cli SAPI to avoid some frameworks to limit the usage of micro SAPI
    with-micro-fake-cli: false
    # Additional patch point injection files (e.g. "path/to/patch.php", list accepted)
    with-added-patch: [ ]
    # Ignore micro extension tests (if you are using micro SAPI, default: false)
    without-micro-ext-test: false
    # UPX pack the binary (default: false)
    with-upx-pack: false
    # Set the micro.exe program icon (only for Windows, default: "")
    with-micro-logo: ""
    # Set micro SAPI as win32 mode, without this, micro SAPI will be compiled as a console application (only for Windows, default: false)
    enable-micro-win32: false

# Download options
download-options:
    # Use custom url for specified sources, format: "{source-name}:{url}" (e.g. "php-src:https://example.com/php-8.4.0.tar.gz")
    custom-url: [ ]
    # Use custom git repo for specified sources, format: "{source-name}:{branch}:{url}" (e.g. "php-src:master:https://github.com/php/php-src.git")
    custom-git: [ ]
    # Retries count for downloading sources (default: 5)
    retry: 5
    # Use pre-built libraries if available (default: false)
    prefer-pre-built: false
    # Do not download from alternative sources (default: false)
    no-alt: false
    # Ignore cache sources, format: "{source-name}" (e.g. "php-src")
    ignore-cache-sources: 'php-src'

craft-options:
    doctor: true
    download: true
    build: true

# Extra environment variables
extra-env:
    # e.g. Use github token to avoid rate limit
    # GITHUB_TOKEN: your-github-token
    SPC_LIBC: glibc
    EXTENSION_DIR: /usr/lib64/php-zts/modules
    SPC_CMD_VAR_PHP_EMBED_TYPE: shared
    SPC_DEFAULT_C_FLAGS: "-fpic -O3 -fstack-protector-strong -fstack-clash-protection"
    SPC_DEFAULT_CXX_FLAGS: "-fpic -O3 -fstack-protector-strong -fstack-clash-protection"
    SPC_OPT_BUILD_ARGS: "--with-config-file-path=/etc/php-zts.ini --with-config-file-scan-dir=/etc/php-zts.d"
    SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS: "-g0 -fstack-protector-strong -O3 -fno-ident -fpic -fpie"
    SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS: "-pie -release zts-82"
    LDFLAGS: "-Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack"
    SPC_CMD_PREFIX_PHP_CONFIGURE: "./configure --prefix= --with-valgrind=no --disable-shared --enable-static --disable-all --disable-cgi --disable-phpdbg --disable-debug --with-pic --disable-dependency-tracking --enable-rtld-now"
    PHP_BUILD_PROVIDER: "Static PHP <https://static-php.dev> #StandWithUkraine"
    NO_CONFIGURE_COMMAND: true

@henderkes
Copy link
Collaborator Author

I can reproduce it when using spc_docker_debug=yes...

I don't have the faintest idea why it's choosing to use that symbol and doesn't fail compiling.

@henderkes
Copy link
Collaborator Author

[root@74269351a747 source]# cd libuv/
[root@74269351a747 libuv]# grep -rnw . -e 'pthread_atfork'
./src/threadpool.c:259:  if (pthread_atfork(NULL, NULL, &reset_once))
./src/unix/os390-syscalls.c:208:  if (pthread_atfork(&before_fork, &after_fork, &child_fork))
./src/unix/signal.c:67:    /* pthread_atfork can register before and after handlers, one
./src/unix/signal.c:73:    if (pthread_atfork(NULL, NULL, &uv__signal_global_reinit))

@crazywhalecc
Copy link
Owner

spc-gnu-docker with SPC_USE_ARCH=aarch64 seems not working so well. I'm struggling with docker now.

@henderkes
Copy link
Collaborator Author

I'm currently trying to track that down, but getting the container in a state where I can debug the package install has been taking 5 hours already. It's soooooooooooooo slow trying to install yum packages.

@henderkes
Copy link
Collaborator Author

https://github.com/libuv/libuv/blob/v1.x/src/unix/signal.c#L73

Well crap. I don't know how to get that to work in Centos 7 aarch. The pthread_atfork literally doesn't exist in any library I searched.

@henderkes
Copy link
Collaborator Author

spc-gnu-docker with SPC_USE_ARCH=aarch64 seems not working so well. I'm struggling with docker now.

I finally got it in a state where I would be able to reproduce it, but all the .repo files have $basearch instead of x86_64. So I'm super confused why building the docker container fails when I try to build it with a Dockerfile, but running the same steps manually works.

@crazywhalecc
Copy link
Owner

crazywhalecc commented Jun 20, 2025

Another context: On my mac docker, I use bin/spc-gnu-docker build bcmath --build-shared=uv --build-cli --debug --enable-zts can successfully build aarch64 ELF uv.so.

@henderkes
Copy link
Collaborator Author

Binary file ./librt-2.17.so matches

I found it. So I need to make sure the libraries are linked in the right order I guess.

@henderkes
Copy link
Collaborator Author

@henderkes
Copy link
Collaborator Author

success:

[09:11:10] [I] [EXEC] /app/buildroot/bin/frankenphp version
[09:11:10] [I]
[09:11:10] [I]    Build complete, used 925.789 s !
[09:11:10] [I]
[09:11:10] [I] Static php binary path (host system): /home/opc/static-php-cli/buildroot/bin/php
[09:11:10] [I] Static php-fpm binary path (host system): /home/opc/static-php-cli/buildroot/bin/php-fpm
[09:11:10] [I] Shared extension [amqp] path (host system): /home/opc/static-php-cli/buildroot/modules/amqp.so
[09:11:10] [I] Shared extension [brotli] path (host system): /home/opc/static-php-cli/buildroot/modules/brotli.so
[09:11:10] [I] Shared extension [bz2] path (host system): /home/opc/static-php-cli/buildroot/modules/bz2.so
[09:11:10] [I] Shared extension [dio] path (host system): /home/opc/static-php-cli/buildroot/modules/dio.so
[09:11:10] [I] Shared extension [ds] path (host system): /home/opc/static-php-cli/buildroot/modules/ds.so
[09:11:10] [I] Shared extension [ev] path (host system): /home/opc/static-php-cli/buildroot/modules/ev.so
[09:11:10] [I] Shared extension [event] path (host system): /home/opc/static-php-cli/buildroot/modules/event.so
[09:11:10] [I] Shared extension [ffi] path (host system): /home/opc/static-php-cli/buildroot/modules/ffi.so
[09:11:10] [I] Shared extension [ftp] path (host system): /home/opc/static-php-cli/buildroot/modules/ftp.so
[09:11:10] [I] Shared extension [gd] path (host system): /home/opc/static-php-cli/buildroot/modules/gd.so
[09:11:10] [I] Shared extension [gettext] path (host system): /home/opc/static-php-cli/buildroot/modules/gettext.so
[09:11:10] [I] Shared extension [gmp] path (host system): /home/opc/static-php-cli/buildroot/modules/gmp.so
[09:11:10] [I] Shared extension [gmssl] path (host system): /home/opc/static-php-cli/buildroot/modules/gmssl.so
[09:11:10] [I] Shared extension [igbinary] path (host system): /home/opc/static-php-cli/buildroot/modules/igbinary.so
[09:11:10] [I] Shared extension [imagick] path (host system): /home/opc/static-php-cli/buildroot/modules/imagick.so
[09:11:10] [I] Shared extension [inotify] path (host system): /home/opc/static-php-cli/buildroot/modules/inotify.so
[09:11:10] [I] Shared extension [intl] path (host system): /home/opc/static-php-cli/buildroot/modules/intl.so
[09:11:10] [I] Shared extension [ldap] path (host system): /home/opc/static-php-cli/buildroot/modules/ldap.so
[09:11:10] [I] Shared extension [lz4] path (host system): /home/opc/static-php-cli/buildroot/modules/lz4.so
[09:11:10] [I] Shared extension [memcache] path (host system): /home/opc/static-php-cli/buildroot/modules/memcache.so
[09:11:10] [I] Shared extension [memcached] path (host system): /home/opc/static-php-cli/buildroot/modules/memcached.so
[09:11:10] [I] Shared extension [mongodb] path (host system): /home/opc/static-php-cli/buildroot/modules/mongodb.so
[09:11:10] [I] Shared extension [msgpack] path (host system): /home/opc/static-php-cli/buildroot/modules/msgpack.so
[09:11:10] [I] Shared extension [mysqli] path (host system): /home/opc/static-php-cli/buildroot/modules/mysqli.so
[09:11:10] [I] Shared extension [mysqlnd] path (host system): /home/opc/static-php-cli/buildroot/modules/mysqlnd.so
[09:11:10] [I] Shared extension [odbc] path (host system): /home/opc/static-php-cli/buildroot/modules/odbc.so
[09:11:10] [I] Shared extension [opentelemetry] path (host system): /home/opc/static-php-cli/buildroot/modules/opentelemetry.so
[09:11:10] [I] Shared extension [parallel] path (host system): /home/opc/static-php-cli/buildroot/modules/parallel.so
[09:11:10] [I] Shared extension [pdo] path (host system): /home/opc/static-php-cli/buildroot/modules/pdo.so
[09:11:10] [I] Shared extension [pdo_mysql] path (host system): /home/opc/static-php-cli/buildroot/modules/pdo_mysql.so
[09:11:10] [I] Shared extension [pdo_odbc] path (host system): /home/opc/static-php-cli/buildroot/modules/pdo_odbc.so
[09:11:10] [I] Shared extension [pdo_pgsql] path (host system): /home/opc/static-php-cli/buildroot/modules/pdo_pgsql.so
[09:11:10] [I] Shared extension [pdo_sqlite] path (host system): /home/opc/static-php-cli/buildroot/modules/pdo_sqlite.so
[09:11:10] [I] Shared extension [pdo_sqlsrv] path (host system): /home/opc/static-php-cli/buildroot/modules/pdo_sqlsrv.so
[09:11:10] [I] Shared extension [pgsql] path (host system): /home/opc/static-php-cli/buildroot/modules/pgsql.so
[09:11:10] [I] Shared extension [protobuf] path (host system): /home/opc/static-php-cli/buildroot/modules/protobuf.so
[09:11:10] [I] Shared extension [rar] path (host system): /home/opc/static-php-cli/buildroot/modules/rar.so
[09:11:10] [I] Shared extension [redis] path (host system): /home/opc/static-php-cli/buildroot/modules/redis.so
[09:11:10] [I] Shared extension [rdkafka] path (host system): /home/opc/static-php-cli/buildroot/modules/rdkafka.so
[09:11:10] [I] Shared extension [shmop] path (host system): /home/opc/static-php-cli/buildroot/modules/shmop.so
[09:11:10] [I] Shared extension [spx] path (host system): /home/opc/static-php-cli/buildroot/modules/spx.so
[09:11:10] [I] Shared extension [sqlite3] path (host system): /home/opc/static-php-cli/buildroot/modules/sqlite3.so
[09:11:10] [I] Shared extension [sqlsrv] path (host system): /home/opc/static-php-cli/buildroot/modules/sqlsrv.so
[09:11:10] [I] Shared extension [ssh2] path (host system): /home/opc/static-php-cli/buildroot/modules/ssh2.so
[09:11:10] [I] Shared extension [swoole] path (host system): /home/opc/static-php-cli/buildroot/modules/swoole.so
[09:11:10] [I] Shared extension [sysvmsg] path (host system): /home/opc/static-php-cli/buildroot/modules/sysvmsg.so
[09:11:10] [I] Shared extension [sysvsem] path (host system): /home/opc/static-php-cli/buildroot/modules/sysvsem.so
[09:11:10] [I] Shared extension [sysvshm] path (host system): /home/opc/static-php-cli/buildroot/modules/sysvshm.so
[09:11:10] [I] Shared extension [tidy] path (host system): /home/opc/static-php-cli/buildroot/modules/tidy.so
[09:11:10] [I] Shared extension [uuid] path (host system): /home/opc/static-php-cli/buildroot/modules/uuid.so
[09:11:10] [I] Shared extension [uv] path (host system): /home/opc/static-php-cli/buildroot/modules/uv.so
[09:11:10] [I] Shared extension [xdebug] path (host system): /home/opc/static-php-cli/buildroot/modules/xdebug.so
[09:11:10] [I] Shared extension [xhprof] path (host system): /home/opc/static-php-cli/buildroot/modules/xhprof.so
[09:11:10] [I] Shared extension [xlswriter] path (host system): /home/opc/static-php-cli/buildroot/modules/xlswriter.so
[09:11:10] [I] Shared extension [xsl] path (host system): /home/opc/static-php-cli/buildroot/modules/xsl.so
[09:11:10] [I] Shared extension [xz] path (host system): /home/opc/static-php-cli/buildroot/modules/xz.so
[09:11:10] [I] Shared extension [yac] path (host system): /home/opc/static-php-cli/buildroot/modules/yac.so
[09:11:10] [I] Shared extension [yaml] path (host system): /home/opc/static-php-cli/buildroot/modules/yaml.so
[09:11:10] [I] Shared extension [zstd] path (host system): /home/opc/static-php-cli/buildroot/modules/zstd.so
[09:11:10] [I] License path (host system): /home/opc/static-php-cli/buildroot/license/

@henderkes henderkes marked this pull request as ready for review June 20, 2025 09:11
@henderkes henderkes requested a review from crazywhalecc June 20, 2025 09:12
@henderkes henderkes merged commit 6c47065 into main Jun 20, 2025
9 checks passed
@henderkes henderkes deleted the fix/aarch64-uv-pthread branch June 20, 2025 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants