Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

static-build (manually, dockerfile with intl) not working #236

Closed
DubbleClick opened this issue Oct 2, 2023 · 10 comments
Closed

static-build (manually, dockerfile with intl) not working #236

DubbleClick opened this issue Oct 2, 2023 · 10 comments

Comments

@DubbleClick
Copy link
Contributor

DubbleClick commented Oct 2, 2023

I was trying to test frankenphp with ldap and c++ extensions (which were only compilable on musl-libc based systems before) but ran into error messages, so I attempted building from the spc/main branch, but ran into the same problem. So I tried to run the dockerfile and lo and behold, it also errors out, albeit with different problems.

The local errors somewhat make sense:

Local:

[root@alma static-php-cli]./bin/spc build intl,openssl,ldap,snappy,mbstring,mbregex,apcu,calendar,curl,dom,exif,fileinfo,iconv,xml,mysqli,pdo_mysql,pdo,sysvsem,sodium,zlib,zip,opcache,pcntl --build-embed --enable-zts --debug
...
*** Warning: Linking the shared library libphp.la against the
*** static library /opt/static-php-cli/buildroot/lib/libzip.a is not portable!

*** Warning: Linking the shared library libphp.la against the
*** static library /opt/static-php-cli/buildroot/lib/libxml2.a is not portable!

...

*** Warning: Linking the shared library libphp.la against the
*** static library /opt/static-php-cli/buildroot/lib/libicudata.a is not portable!
libtool: link: warning: library `/usr/local/musl/x86_64-linux-musl/lib/libstdc++.la' was moved.
copying selected object files to avoid basename conflicts...
Installing PHP SAPI module:       embed
[11:48:15] [INFO] Build complete, used 50.985 s !
[11:48:15] [DEBU] Removing path recursively: "/opt/static-php-cli/buildroot/license"
[11:48:15] [DEBU] scanning directory /opt/static-php-cli/buildroot/license
[11:48:15] [DEBU] Making new directory recursive: /opt/static-php-cli/buildroot/license
[11:48:15] [INFO] License path: /opt/static-php-cli/buildroot/license/

...

[root@alma frankenphp]# CGO_CFLAGS="$(/opt/static-main/buildroot/bin/php-config --includes | sed s#-I/#-I/opt/static-main/buildroot/#g)"     CGO_LDFLAGS="-DFRANKENPHP_VERSION=$FRANKENPHP_VERSION $(/opt/static-main/buildroot/bin/php-config --ldflags) $(/opt/static-main/buildroot/bin/php-config --libs | sed -e 's/-lgcc_s//g') -L/usr/local/musl/lib -L /usr/local/musl/x86_64-linux-musl/lib"     LIBPHP_VERSION="$(/opt/static-main/buildroot/bin/php-config --version)"     go build -buildmode=pie -tags "cgo netgo osusergo static_build" -ldflags "-linkmode=external -extldflags -static-pie -s -w -X 'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP $FRANKENPHP_VERSION PHP $LIBPHP_VERSION Caddy'"
# github.com/dunglas/frankenphp/caddy/frankenphp
/usr/local/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/usr/bin/ld: /opt/static-main/buildroot/lib/libphp.a(spl_exceptions.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: /opt/static-main/buildroot/lib/libphp.a(head.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: /opt/static-main/buildroot/lib/libphp.a(url.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: /opt/static-main/buildroot/lib/libphp.a(TSRM.o): relocation R_X86_64_32 against `.bss' can not be used when making a PIE object; recompile with -fPIE
... about 500 more lines like this

Docker:

[root@alma frankenphp-main] docker buildx bake --load --set static-builder.args.PHP_EXTENSIONS=intl,openssl,ldap,snappy,mbstring,mbregex,apcu,calendar,curl,dom,exif,fileinfo,iconv,xml,mysqli,pdo_mysql,pdo,sysvsem,sodium,zlib,zip,opcache,pcntl static-builder
... (spc build succeeds)
 => CANCELED [stage-0  1/17] RUN apk update;     apk add --no-cache         autoconf         automake         bas  0.8s
ERROR: failed to solve: Canceled: context canceled
[root@alma frankenphp-main]# docker buildx bake --load --set static-builder.args.PHP_EXTENSIONS=intl,openssl,ldap,snappy,mbstring,mbregex,apcu,calendar,curl,dom,exif,fileinfo,iconv,xml,mysqli,pdo_mysql,pdo,sysvsem,sodium,zlib,zip,opcache,pcntl static-builder
[+] Building 377.3s (25/25) FINISHED                                                                     docker:default
 => [internal] load build definition from static-builder.Dockerfile                                                0.0s
 => => transferring dockerfile: 2.90kB                                                                             0.0s
 => [internal] load .dockerignore                                                                                  0.0s
 => => transferring context: 186B                                                                                  0.0s
 => resolve image config for docker.io/docker/dockerfile:1                                                         0.4s
 => CACHED docker-image://docker.io/docker/dockerfile:1@sha256:ac85f380a63b13dfcefa89046420e1781752bab202122f8f50  0.0s
 => [context golang-base] load metadata for golang:1.21-alpine                                                     0.4s
 => [internal] load metadata for docker.io/composer/composer:2-bin                                                 0.4s
 => CACHED [context golang-base] golang:1.21-alpine                                                                0.2s
 => => resolve docker.io/library/golang:1.21-alpine                                                                0.2s
 => [internal] load build context                                                                                  0.0s
 => => transferring context: 2.11kB                                                                                0.0s
 => CACHED FROM docker.io/composer/composer:2-bin@sha256:9eddaebb35d548fa0d40d079477ca0eb2e4e82762f29e98ec29d5eac  0.0s
 => [stage-0  1/17] RUN apk update;     apk add --no-cache         autoconf         automake         bash          6.4s
 => [stage-0  2/17] COPY --from=composer/composer:2-bin --link /composer /usr/bin/composer                         0.0s
 => [stage-0  3/17] WORKDIR /static-php-cli                                                                        0.0s
 => [stage-0  4/17] RUN git clone --depth=1 https://github.com/crazywhalecc/static-php-cli . &&     composer inst  1.7s
 => [stage-0  5/17] RUN --mount=type=secret,id=github-token GITHUB_TOKEN=$(cat /run/secrets/github-token) ./bin  125.1s
 => [stage-0  6/17] RUN ./bin/spc build --build-embed --enable-zts "intl,openssl,ldap,snappy,mbstring,mbregex,a  195.8s
 => [stage-0  7/17] WORKDIR /go/src/app                                                                            0.0s
 => [stage-0  8/17] COPY go.mod go.sum ./                                                                          0.0s
 => [stage-0  9/17] RUN go mod graph | awk '{if ($1 !~ "@") print $2}' | xargs go get                              2.6s
 => [stage-0 10/17] RUN mkdir caddy && cd caddy                                                                    0.1s
 => [stage-0 11/17] COPY caddy/go.mod caddy/go.sum ./caddy/                                                        0.0s
 => [stage-0 12/17] RUN cd caddy && go mod graph | awk '{if ($1 !~ "@") print $2}' | xargs go get                 31.5s
 => [stage-0 13/17] COPY *.* ./                                                                                    0.0s
 => [stage-0 14/17] COPY caddy caddy                                                                               0.0s
 => [stage-0 15/17] COPY C-Thread-Pool C-Thread-Pool                                                               0.0s
 => ERROR [stage-0 16/17] RUN cd caddy/frankenphp &&     CGO_CFLAGS="$(/static-php-cli/buildroot/bin/php-config   12.7s
------
 > [stage-0 16/17] RUN cd caddy/frankenphp &&     CGO_CFLAGS="$(/static-php-cli/buildroot/bin/php-config --includes | sed s#-I/#-I/static-php-cli/buildroot/#g)"     CGO_LDFLAGS="-DFRANKENPHP_VERSION=dev $(/static-php-cli/buildroot/bin/php-config --ldflags) $(/static-php-cli/buildroot/bin/php-config --libs | sed -e 's/-lgcc_s//g')"     LIBPHP_VERSION="$(/static-php-cli/buildroot/bin/php-config --version)"     go build -buildmode=pie -tags "cgo netgo osusergo static_build" -ldflags "-linkmode=external -extldflags -static-pie -s -w -X 'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP dev PHP $LIBPHP_VERSION Caddy'" &&     ./frankenphp version:
12.58 # github.com/dunglas/frankenphp/caddy/frankenphp
12.58 /usr/local/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /static-php-cli/buildroot/lib/pkgconfig/../../lib/libicui18n.a(number_decimalquantity.ao):(.data.rel.ro._ZTIN6icu_736number4impl15DecimalQuantityE[_ZTIN6icu_736number4impl15DecimalQuantityE]+0x0): undefined reference to `vtable for __cxxabiv1::__vmi_class_type_info'
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /static-php-cli/buildroot/lib/pkgconfig/../../lib/libicui18n.a(number_fluent.ao):(.data.rel.ro._ZTIN6icu_736number4impl13EmptyModifierE[_ZTIN6icu_736number4impl13EmptyModifierE]+0x0): undefined reference to `vtable for __cxxabiv1::__vmi_class_type_info'
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /static-php-cli/buildroot/lib/pkgconfig/../../lib/libicui18n.a(number_longnames.ao):(.data.rel.ro._ZTIN6icu_736number4impl15LongNameHandlerE[_ZTIN6icu_736number4impl15LongNameHandlerE]+0x0): undefined reference to `vtable for __cxxabiv1::__vmi_class_type_info'
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /static-php-cli/buildroot/lib/pkgconfig/../../lib/libicui18n.a(number_longnames.ao):(.data.rel.ro._ZTIN6icu_736number4impl24MixedUnitLongNameHandlerE[_ZTIN6icu_736number4impl24MixedUnitLongNameHandlerE]+0x0): undefined reference to `vtable for __cxxabiv1::__vmi_class_type_info'
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /static-php-cli/buildroot/lib/pkgconfig/../../lib/libicui18n.a(number_longnames.ao):(.data.rel.ro._ZTIN6icu_736number4impl19LongNameMultiplexerE[_ZTIN6icu_736number4impl19LongNameMultiplexerE]+0x0): undefined reference to `vtable for __cxxabiv1::__vmi_class_type_info'
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /static-php-cli/buildroot/lib/pkgconfig/../../lib/libicui18n.a(number_mapper.ao):(.data.rel.ro._ZTIN6icu_736number4impl30PropertiesAffixPatternProviderE[_ZTIN6icu_736number4impl30PropertiesAffixPatternProviderE]+0x0): more undefined references to `vtable for __cxxabiv1::__vmi_class_type_info' follow
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /static-php-cli/buildroot/lib/pkgconfig/../../lib/libicuuc.a(umutex.ao): in function `std::once_flag::_Prepare_execution::_Prepare_execution<std::call_once<void (&)()>(std::once_flag&, void (&)())::{lambda()#1}>(void (&)())::{lambda()#1}::_FUN()':
12.58 umutex.cpp:(.text._ZZNSt9once_flag18_Prepare_executionC4IZSt9call_onceIRFvvEJEEvRS_OT_DpOT0_EUlvE_EERS6_ENUlvE_4_FUNEv[_ZZNSt9once_flag18_Prepare_executionC4IZSt9call_onceIRFvvEJEEvRS_OT_DpOT0_EUlvE_EERS6_ENUlvE_4_FUNEv]+0x3): undefined reference to `std::__once_callable'
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /static-php-cli/buildroot/lib/pkgconfig/../../lib/libicuuc.a(umutex.ao): in function `umtx_init':
12.58 umutex.cpp:(.text.umtx_init+0x37): undefined reference to `std::condition_variable::condition_variable()'
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /static-php-cli/buildroot/lib/pkgconfig/../../lib/libicuuc.a(umutex.ao): in function `umtx_cleanup':
12.58 umutex.cpp:(.text.umtx_cleanup+0xc): undefined reference to `std::condition_variable::~condition_variable()'
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /static-php-cli/buildroot/lib/pkgconfig/../../lib/libicuuc.a(umutex.ao): in function `icu_73::UMutex::getMutex()':
12.58 umutex.cpp:(.text._ZN6icu_736UMutex8getMutexEv+0x5a): undefined reference to `std::__once_callable'
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: umutex.cpp:(.text._ZN6icu_736UMutex8getMutexEv+0x6c): undefined reference to `std::__once_call'
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: umutex.cpp:(.text._ZN6icu_736UMutex8getMutexEv+0x8e): undefined reference to `__once_proxy'
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: umutex.cpp:(.text._ZN6icu_736UMutex8getMutexEv+0x11d): undefined reference to `std::__throw_system_error(int)'
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: umutex.cpp:(.text._ZN6icu_736UMutex8getMutexEv+0x124): undefined reference to `std::__throw_system_error(int)'
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /static-php-cli/buildroot/lib/pkgconfig/../../lib/libicuuc.a(umutex.ao): in function `umtx_lock_73':
12.58 umutex.cpp:(.text.umtx_lock_73+0x3a): undefined reference to `std::__throw_system_error(int)'
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /static-php-cli/buildroot/lib/pkgconfig/../../lib/libicuuc.a(umutex.ao): in function `icu_73::umtx_initImplPreInit(icu_73::UInitOnce&)':
12.58 umutex.cpp:(.text._ZN6icu_7320umtx_initImplPreInitERNS_9UInitOnceE+0x10): undefined reference to `std::__once_callable'
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: umutex.cpp:(.text._ZN6icu_7320umtx_initImplPreInitERNS_9UInitOnceE+0x17): undefined reference to `std::__once_call'
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: umutex.cpp:(.text._ZN6icu_7320umtx_initImplPreInitERNS_9UInitOnceE+0x4a): undefined reference to `__once_proxy'
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: umutex.cpp:(.text._ZN6icu_7320umtx_initImplPreInitERNS_9UInitOnceE+0xbb): undefined reference to `std::condition_variable::wait(std::unique_lock<std::mutex>&)'
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: umutex.cpp:(.text._ZN6icu_7320umtx_initImplPreInitERNS_9UInitOnceE+0x115): undefined reference to `std::__throw_system_error(int)'
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: umutex.cpp:(.text._ZN6icu_7320umtx_initImplPreInitERNS_9UInitOnceE+0x11f): undefined reference to `std::__throw_system_error(int)'
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: umutex.cpp:(.text._ZN6icu_7320umtx_initImplPreInitERNS_9UInitOnceE+0x126): undefined reference to `std::__throw_system_error(int)'
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /static-php-cli/buildroot/lib/pkgconfig/../../lib/libicuuc.a(umutex.ao): in function `icu_73::umtx_initImplPostInit(icu_73::UInitOnce&)':
12.58 umutex.cpp:(.text._ZN6icu_7321umtx_initImplPostInitERNS_9UInitOnceE+0x47): undefined reference to `std::__throw_system_error(int)'
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: umutex.cpp:(.text._ZN6icu_7321umtx_initImplPostInitERNS_9UInitOnceE+0x4e): undefined reference to `std::__throw_system_error(int)'
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: umutex.cpp:(.text._ZN6icu_7321umtx_initImplPostInitERNS_9UInitOnceE+0x3d): undefined reference to `std::condition_variable::notify_all()'
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /static-php-cli/buildroot/lib/pkgconfig/../../lib/libicuuc.a(unifiedcache.ao): in function `icu_73::UnifiedCache::setEvictionPolicy(int, int, UErrorCode&)':
12.58 unifiedcache.cpp:(.text._ZN6icu_7312UnifiedCache17setEvictionPolicyEiiR10UErrorCode+0x6c): undefined reference to `std::__throw_system_error(int)'
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /static-php-cli/buildroot/lib/pkgconfig/../../lib/libicuuc.a(unifiedcache.ao): in function `icu_73::UnifiedCache::unusedCount() const':
12.58 unifiedcache.cpp:(.text._ZNK6icu_7312UnifiedCache11unusedCountEv+0x3e): undefined reference to `std::__throw_system_error(int)'
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /static-php-cli/buildroot/lib/pkgconfig/../../lib/libicuuc.a(unifiedcache.ao): in function `icu_73::UnifiedCache::autoEvictedCount() const':
12.58 unifiedcache.cpp:(.text._ZNK6icu_7312UnifiedCache16autoEvictedCountEv+0x35): undefined reference to `std::__throw_system_error(int)'
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /static-php-cli/buildroot/lib/pkgconfig/../../lib/libicuuc.a(unifiedcache.ao): in function `icu_73::UnifiedCache::keyCount() const':
12.58 unifiedcache.cpp:(.text._ZNK6icu_7312UnifiedCache8keyCountEv+0x3b): undefined reference to `std::__throw_system_error(int)'
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /static-php-cli/buildroot/lib/pkgconfig/../../lib/libicuuc.a(unifiedcache.ao): in function `icu_73::UnifiedCache::flush() const':
12.58 unifiedcache.cpp:(.text._ZNK6icu_7312UnifiedCache5flushEv+0x178): undefined reference to `std::__throw_system_error(int)'
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /static-php-cli/buildroot/lib/pkgconfig/../../lib/libicuuc.a(unifiedcache.ao):unifiedcache.cpp:(.text._ZN6icu_7312UnifiedCacheD2Ev+0x138): more undefined references to `std::__throw_system_error(int)' follow
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /static-php-cli/buildroot/lib/pkgconfig/../../lib/libicuuc.a(unifiedcache.ao): in function `unifiedcache_cleanup':
12.58 unifiedcache.cpp:(.text.unifiedcache_cleanup+0x56): undefined reference to `std::condition_variable::~condition_variable()'
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /static-php-cli/buildroot/lib/pkgconfig/../../lib/libicuuc.a(unifiedcache.ao): in function `icu_73::UnifiedCache::getInstance(UErrorCode&)':
12.58 unifiedcache.cpp:(.text._ZN6icu_7312UnifiedCache11getInstanceER10UErrorCode+0xda): undefined reference to `std::condition_variable::condition_variable()'
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /static-php-cli/buildroot/lib/pkgconfig/../../lib/libicuuc.a(unifiedcache.ao): in function `icu_73::UnifiedCache::handleUnreferencedObject() const':
12.58 unifiedcache.cpp:(.text._ZNK6icu_7312UnifiedCache24handleUnreferencedObjectEv+0x3a): undefined reference to `std::__throw_system_error(int)'
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /static-php-cli/buildroot/lib/pkgconfig/../../lib/libicuuc.a(unifiedcache.ao): in function `icu_73::UnifiedCache::_poll(icu_73::CacheKeyBase const&, icu_73::SharedObject const*&, UErrorCode&) const':
12.58 unifiedcache.cpp:(.text._ZNK6icu_7312UnifiedCache5_pollERKNS_12CacheKeyBaseERPKNS_12SharedObjectER10UErrorCode+0x149): undefined reference to `std::condition_variable::wait(std::unique_lock<std::mutex>&)'
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: unifiedcache.cpp:(.text._ZNK6icu_7312UnifiedCache5_pollERKNS_12CacheKeyBaseERPKNS_12SharedObjectER10UErrorCode+0x231): undefined reference to `std::__throw_system_error(int)'
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: unifiedcache.cpp:(.text._ZNK6icu_7312UnifiedCache5_pollERKNS_12CacheKeyBaseERPKNS_12SharedObjectER10UErrorCode+0x238): undefined reference to `std::__throw_system_error(int)'
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /static-php-cli/buildroot/lib/pkgconfig/../../lib/libicuuc.a(unifiedcache.ao): in function `icu_73::UnifiedCache::_put(UHashElement const*, icu_73::SharedObject const*, UErrorCode) const':
12.58 unifiedcache.cpp:(.text._ZNK6icu_7312UnifiedCache4_putEPK12UHashElementPKNS_12SharedObjectE10UErrorCode+0x4d): undefined reference to `std::condition_variable::notify_all()'
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: unifiedcache.cpp:(.text._ZNK6icu_7312UnifiedCache4_putEPK12UHashElementPKNS_12SharedObjectE10UErrorCode+0x7a): undefined reference to `std::condition_variable::notify_all()'
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: unifiedcache.cpp:(.text._ZNK6icu_7312UnifiedCache4_putEPK12UHashElementPKNS_12SharedObjectE10UErrorCode+0x91): undefined reference to `std::condition_variable::notify_all()'
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /static-php-cli/buildroot/lib/pkgconfig/../../lib/libicuuc.a(unifiedcache.ao): in function `icu_73::UnifiedCache::_putIfAbsentAndGet(icu_73::CacheKeyBase const&, icu_73::SharedObject const*&, UErrorCode&) const':
12.58 unifiedcache.cpp:(.text._ZNK6icu_7312UnifiedCache18_putIfAbsentAndGetERKNS_12CacheKeyBaseERPKNS_12SharedObjectER10UErrorCode+0xba): undefined reference to `std::condition_variable::notify_all()'
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: unifiedcache.cpp:(.text._ZNK6icu_7312UnifiedCache18_putIfAbsentAndGetERKNS_12CacheKeyBaseERPKNS_12SharedObjectER10UErrorCode+0x209): undefined reference to `std::__throw_system_error(int)'
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /static-php-cli/buildroot/lib/pkgconfig/../../lib/libicui18n.a(numparse_validators.ao):(.data.rel.ro._ZTIN6icu_738numparse4impl21RequireAffixValidatorE[_ZTIN6icu_738numparse4impl21RequireAffixValidatorE]+0x0): undefined reference to `vtable for __cxxabiv1::__vmi_class_type_info'
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /static-php-cli/buildroot/lib/pkgconfig/../../lib/libicui18n.a(numparse_validators.ao):(.data.rel.ro._ZTIN6icu_738numparse4impl24RequireCurrencyValidatorE[_ZTIN6icu_738numparse4impl24RequireCurrencyValidatorE]+0x0): undefined reference to `vtable for __cxxabiv1::__vmi_class_type_info'
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /static-php-cli/buildroot/lib/pkgconfig/../../lib/libicui18n.a(numparse_validators.ao):(.data.rel.ro._ZTIN6icu_738numparse4impl32RequireDecimalSeparatorValidatorE[_ZTIN6icu_738numparse4impl32RequireDecimalSeparatorValidatorE]+0x0): undefined reference to `vtable for __cxxabiv1::__vmi_class_type_info'
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /static-php-cli/buildroot/lib/pkgconfig/../../lib/libicui18n.a(numparse_validators.ao):(.data.rel.ro._ZTIN6icu_738numparse4impl22RequireNumberValidatorE[_ZTIN6icu_738numparse4impl22RequireNumberValidatorE]+0x0): undefined reference to `vtable for __cxxabiv1::__vmi_class_type_info'
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /static-php-cli/buildroot/lib/pkgconfig/../../lib/libicui18n.a(numparse_validators.ao):(.data.rel.ro._ZTIN6icu_738numparse4impl22MultiplierParseHandlerE[_ZTIN6icu_738numparse4impl22MultiplierParseHandlerE]+0x0): undefined reference to `vtable for __cxxabiv1::__vmi_class_type_info'
12.58 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /static-php-cli/buildroot/lib/pkgconfig/../../lib/libicuuc.a(unifilt.ao):(.data.rel.ro._ZTIN6icu_7313UnicodeFilterE[_ZTIN6icu_7313UnicodeFilterE]+0x0): more undefined references to `vtable for __cxxabiv1::__vmi_class_type_info' follow
12.58 collect2: error: ld returned 1 exit status
12.58
------
static-builder.Dockerfile:78
--------------------
  77 |
  78 | >>> RUN cd caddy/frankenphp && \
  79 | >>>     CGO_CFLAGS="$(/static-php-cli/buildroot/bin/php-config --includes | sed s#-I/#-I/static-php-cli/buildroot/#g)" \
  80 | >>>     CGO_LDFLAGS="-DFRANKENPHP_VERSION=$FRANKENPHP_VERSION $(/static-php-cli/buildroot/bin/php-config --ldflags) $(/static-php-cli/buildroot/bin/php-config --libs | sed -e 's/-lgcc_s//g')" \
  81 | >>>     LIBPHP_VERSION="$(/static-php-cli/buildroot/bin/php-config --version)" \
  82 | >>>     go build -buildmode=pie -tags "cgo netgo osusergo static_build" -ldflags "-linkmode=external -extldflags -static-pie -s -w -X 'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP $FRANKENPHP_VERSION PHP $LIBPHP_VERSION Caddy'" && \
  83 | >>>     ./frankenphp version
  84 |
--------------------
ERROR: failed to solve: process "/bin/sh -c cd caddy/frankenphp &&     CGO_CFLAGS=\"$(/static-php-cli/buildroot/bin/php-config --includes | sed s#-I/#-I/static-php-cli/buildroot/#g)\"     CGO_LDFLAGS=\"-DFRANKENPHP_VERSION=$FRANKENPHP_VERSION $(/static-php-cli/buildroot/bin/php-config --ldflags) $(/static-php-cli/buildroot/bin/php-config --libs | sed -e 's/-lgcc_s//g')\"     LIBPHP_VERSION=\"$(/static-php-cli/buildroot/bin/php-config --version)\"     go build -buildmode=pie -tags \"cgo netgo osusergo static_build\" -ldflags \"-linkmode=external -extldflags -static-pie -s -w -X 'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP $FRANKENPHP_VERSION PHP $LIBPHP_VERSION Caddy'\" &&     ./frankenphp version" did not complete successfully: exit code: 1

Questions:

a) did you run into the same -fPIE error messages before or is that maybe specific to RHEL distros?
b) did you run into the same *** Warning: Linking the shared library libphp.la against the *** static library /opt/static-php-cli/buildroot/lib/libldap.a is not portable! message at some point and if so, how did you fix it?
c) did you try compiling static frankenphp on non-alpine before?
d) it's the intl extension (icu lib) causing docker to fail compiling, but I see intl listed in the extensions it would build by default.

@DubbleClick
Copy link
Contributor Author

Edit: Building locally works with

CC='x86_64-linux-musl-gcc' CXX='x86_64-linux-musl-g++' \
CGO_CFLAGS="$(/opt/static-php-cli/buildroot/bin/php-config --includes | sed s#-I/#-I/opt/static-php-cli/buildroot/#g)"  \
CGO_LDFLAGS="-DFRANKENPHP_VERSION=$FRANKENPHP_VERSION $(/opt/static-php-cli/buildroot/bin/php-config --ldflags) $(/opt/static-php-cli/buildroot/bin/php-config --libs | sed -e 's/-lgcc_s//g') -L/usr/local/musl/lib -L /usr/local/musl/x86_64-linux-musl/lib"  \
LIBPHP_VERSION="$(/opt/static-php-cli/buildroot/bin/php-config --version)" \
go build -tags "cgo netgo osusergo static_build" -ldflags "-linkmode=external -extldflags -static -s -w -X 'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP $FRANKENPHP_VERSION PHP $LIBPHP_VERSION Caddy'"

i.e. with -buildmode=pie removed and -static-pie changed to -static.
Same problem as in the static-builder.Docker with intl, however.

@DubbleClick DubbleClick changed the title static-build (manually, dockerfile) not working static-build (manually, dockerfile with intl) not working Oct 2, 2023
@DubbleClick
Copy link
Contributor Author

edit: with certain extension selections it actually seems necessary to pass -lstdc++ to LD_FLAGS (yes, to build frankenphp).

@dunglas
Copy link
Owner

dunglas commented Oct 3, 2023

That's weird because we use this Dockerfile in our CI and it's green.
Regarding C++, it's intended if you use extensions written in C++.

@DubbleClick
Copy link
Contributor Author

That's weird because we use this Dockerfile in our CI and it's green. Regarding C++, it's intended if you use extensions written in C++.

Yep, I figured it out why. When the pgsql extension is used, it links these parts into the embed api, when it's not, you need to link any program using the embed api with -libstdc++. The same thing happens with openssl, which requires lib zlib. When the extension zlib is used, it statically links the zlib methods into the embed api, if the zlib extension isn't enabled you need to link any program that uses the embed api with -lz.

I'm not really sure how we can force the linker to always statically link everything. I'm not even sure why it doesn't do it in the first place, or why adding an extension convinces the linker to do it.

@DubbleClick
Copy link
Contributor Author

Wow, it gets even weirder. php-config does list -lstdc++ as a dependency with just intl active.

libs=" -lstdc++ -lrt -lm -ldl -lpthread -lssl -lcrypto -lz -licuio -licui18n -licuuc -licudata"
This is the default output for php-config.

Results in

[root@alma frankenphp]# CC='x86_64-linux-musl-gcc' CXX='x86_64-linux-musl-g++' CGO_CFLAGS="$(/opt/static-php-cli/buildroot/bin/php-config --includes | sed s#-I/#-I/opt/static-php-cli/buildroot/#g)"     CGO_LDFLAGS="-DFRANKENPHP_VERSION=$FRANKENPHP_VERSION $(/opt/static-php-cli/buildroot/bin/php-config --ldflags) $(/opt/static-php-cli/buildroot/bin/php-config --libs | sed -e 's/-lgcc_s//g') -L/usr/local/musl/lib -L/usr/local/musl/x86_64-linux-musl/lib"     LIBPHP_VERSION="$(/opt/static-php-cli/buildroot/bin/php-config --version)"     go build -tags "cgo netgo osusergo static_build" -ldflags "-linkmode=external -extldflags -static -s -w -X 'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP $FRANKENPHP_VERSION PHP $LIBPHP_VERSION Caddy'"
# github.com/dunglas/frankenphp/caddy/frankenphp
/usr/local/go/pkg/tool/linux_amd64/link: running x86_64-linux-musl-gcc failed: exit status 1
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: /opt/static-php-cli/buildroot/lib/libicui18n.a(dtptngen.ao): in function `icu_73::DateTimePatternGenerator::getDateTimeFormat() const [clone .cold]':
dtptngen.cpp:(.text.unlikely._ZNK6icu_7324DateTimePatternGenerator17getDateTimeFormatEv+0x6): undefined reference to `__cxa_guard_abort'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: /opt/static-php-cli/buildroot/lib/libicui18n.a(dtptngen.ao): in function `icu_73::DateTimePatternGenerator::getDateTimeFormat() const':
dtptngen.cpp:(.text._ZNK6icu_7324DateTimePatternGenerator17getDateTimeFormatEv+0x2e): undefined reference to `__cxa_guard_acquire'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: dtptngen.cpp:(.text._ZNK6icu_7324DateTimePatternGenerator17getDateTimeFormatEv+0x72): undefined reference to `__cxa_guard_release'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: /opt/static-php-cli/buildroot/lib/libicui18n.a(dtptngen.ao): in function `icu_73::DateTimePatternGenerator::getDateTimeFormat(UDateFormatStyle, UErrorCode&) const [clone .cold]':
dtptngen.cpp:(.text.unlikely._ZNK6icu_7324DateTimePatternGenerator17getDateTimeFormatE16UDateFormatStyleR10UErrorCode+0x6): undefined reference to `__cxa_guard_abort'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: /opt/static-php-cli/buildroot/lib/libicui18n.a(dtptngen.ao): in function `icu_73::DateTimePatternGenerator::getDateTimeFormat(UDateFormatStyle, UErrorCode&) const':
dtptngen.cpp:(.text._ZNK6icu_7324DateTimePatternGenerator17getDateTimeFormatE16UDateFormatStyleR10UErrorCode+0x4e): undefined reference to `__cxa_guard_acquire'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: dtptngen.cpp:(.text._ZNK6icu_7324DateTimePatternGenerator17getDateTimeFormatE16UDateFormatStyleR10UErrorCode+0x92): undefined reference to `__cxa_guard_release'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: /opt/static-php-cli/buildroot/lib/libicui18n.a(number_decimalquantity.ao):(.rodata._ZTIN6icu_736number4impl15DecimalQuantityE[_ZTIN6icu_736number4impl15DecimalQuantityE]+0x0): undefined reference to `vtable for __cxxabiv1::__vmi_class_type_info'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: /opt/static-php-cli/buildroot/lib/libicui18n.a(number_fluent.ao):(.rodata._ZTIN6icu_736number4impl13EmptyModifierE[_ZTIN6icu_736number4impl13EmptyModifierE]+0x0): undefined reference to `vtable for __cxxabiv1::__vmi_class_type_info'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: /opt/static-php-cli/buildroot/lib/libicui18n.a(number_longnames.ao):(.rodata._ZTIN6icu_736number4impl15LongNameHandlerE[_ZTIN6icu_736number4impl15LongNameHandlerE]+0x0): undefined reference to `vtable for __cxxabiv1::__vmi_class_type_info'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: /opt/static-php-cli/buildroot/lib/libicui18n.a(number_longnames.ao):(.rodata._ZTIN6icu_736number4impl24MixedUnitLongNameHandlerE[_ZTIN6icu_736number4impl24MixedUnitLongNameHandlerE]+0x0): undefined reference to `vtable for __cxxabiv1::__vmi_class_type_info'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: /opt/static-php-cli/buildroot/lib/libicui18n.a(number_longnames.ao):(.rodata._ZTIN6icu_736number4impl19LongNameMultiplexerE[_ZTIN6icu_736number4impl19LongNameMultiplexerE]+0x0): undefined reference to `vtable for __cxxabiv1::__vmi_class_type_info'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: /opt/static-php-cli/buildroot/lib/libicui18n.a(number_mapper.ao):(.rodata._ZTIN6icu_736number4impl30PropertiesAffixPatternProviderE[_ZTIN6icu_736number4impl30PropertiesAffixPatternProviderE]+0x0): more undefined references to `vtable for __cxxabiv1::__vmi_class_type_info' follow
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: /opt/static-php-cli/buildroot/lib/libicuuc.a(unifiedcache.ao): in function `icu_73::UnifiedCache::setEvictionPolicy(int, int, UErrorCode&)':
unifiedcache.cpp:(.text._ZN6icu_7312UnifiedCache17setEvictionPolicyEiiR10UErrorCode+0x6c): undefined reference to `std::__throw_system_error(int)'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: /opt/static-php-cli/buildroot/lib/libicuuc.a(unifiedcache.ao): in function `icu_73::UnifiedCache::unusedCount() const':
unifiedcache.cpp:(.text._ZNK6icu_7312UnifiedCache11unusedCountEv+0x3c): undefined reference to `std::__throw_system_error(int)'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: /opt/static-php-cli/buildroot/lib/libicuuc.a(unifiedcache.ao): in function `icu_73::UnifiedCache::autoEvictedCount() const':
unifiedcache.cpp:(.text._ZNK6icu_7312UnifiedCache16autoEvictedCountEv+0x31): undefined reference to `std::__throw_system_error(int)'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: /opt/static-php-cli/buildroot/lib/libicuuc.a(unifiedcache.ao): in function `icu_73::UnifiedCache::keyCount() const':
unifiedcache.cpp:(.text._ZNK6icu_7312UnifiedCache8keyCountEv+0x39): undefined reference to `std::__throw_system_error(int)'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: /opt/static-php-cli/buildroot/lib/libicuuc.a(unifiedcache.ao): in function `icu_73::UnifiedCache::flush() const':
unifiedcache.cpp:(.text._ZNK6icu_7312UnifiedCache5flushEv+0x177): undefined reference to `std::__throw_system_error(int)'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: /opt/static-php-cli/buildroot/lib/libicuuc.a(unifiedcache.ao):unifiedcache.cpp:(.text._ZN6icu_7312UnifiedCacheD2Ev+0x138): more undefined references to `std::__throw_system_error(int)' follow
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: /opt/static-php-cli/buildroot/lib/libicuuc.a(unifiedcache.ao): in function `unifiedcache_cleanup':
unifiedcache.cpp:(.text.unifiedcache_cleanup+0x58): undefined reference to `std::condition_variable::~condition_variable()'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: /opt/static-php-cli/buildroot/lib/libicuuc.a(unifiedcache.ao): in function `icu_73::UnifiedCache::getInstance(UErrorCode&)':
unifiedcache.cpp:(.text._ZN6icu_7312UnifiedCache11getInstanceER10UErrorCode+0x8b): undefined reference to `std::condition_variable::condition_variable()'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: /opt/static-php-cli/buildroot/lib/libicuuc.a(unifiedcache.ao): in function `icu_73::UnifiedCache::handleUnreferencedObject() const':
unifiedcache.cpp:(.text._ZNK6icu_7312UnifiedCache24handleUnreferencedObjectEv+0x3c): undefined reference to `std::__throw_system_error(int)'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: /opt/static-php-cli/buildroot/lib/libicuuc.a(unifiedcache.ao): in function `icu_73::UnifiedCache::_poll(icu_73::CacheKeyBase const&, icu_73::SharedObject const*&, UErrorCode&) const':
unifiedcache.cpp:(.text._ZNK6icu_7312UnifiedCache5_pollERKNS_12CacheKeyBaseERPKNS_12SharedObjectER10UErrorCode+0x88): undefined reference to `std::condition_variable::wait(std::unique_lock<std::mutex>&)'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: unifiedcache.cpp:(.text._ZNK6icu_7312UnifiedCache5_pollERKNS_12CacheKeyBaseERPKNS_12SharedObjectER10UErrorCode+0x1ca): undefined reference to `std::__throw_system_error(int)'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: unifiedcache.cpp:(.text._ZNK6icu_7312UnifiedCache5_pollERKNS_12CacheKeyBaseERPKNS_12SharedObjectER10UErrorCode+0x1d1): undefined reference to `std::__throw_system_error(int)'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: /opt/static-php-cli/buildroot/lib/libicuuc.a(unifiedcache.ao): in function `icu_73::UnifiedCache::_put(UHashElement const*, icu_73::SharedObject const*, UErrorCode) const':
unifiedcache.cpp:(.text._ZNK6icu_7312UnifiedCache4_putEPK12UHashElementPKNS_12SharedObjectE10UErrorCode+0x40): undefined reference to `std::condition_variable::notify_all()'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: unifiedcache.cpp:(.text._ZNK6icu_7312UnifiedCache4_putEPK12UHashElementPKNS_12SharedObjectE10UErrorCode+0x6b): undefined reference to `std::condition_variable::notify_all()'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: unifiedcache.cpp:(.text._ZNK6icu_7312UnifiedCache4_putEPK12UHashElementPKNS_12SharedObjectE10UErrorCode+0x81): undefined reference to `std::condition_variable::notify_all()'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: /opt/static-php-cli/buildroot/lib/libicuuc.a(unifiedcache.ao): in function `icu_73::UnifiedCache::_putIfAbsentAndGet(icu_73::CacheKeyBase const&, icu_73::SharedObject const*&, UErrorCode&) const':
unifiedcache.cpp:(.text._ZNK6icu_7312UnifiedCache18_putIfAbsentAndGetERKNS_12CacheKeyBaseERPKNS_12SharedObjectER10UErrorCode+0x9d): undefined reference to `std::condition_variable::notify_all()'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: unifiedcache.cpp:(.text._ZNK6icu_7312UnifiedCache18_putIfAbsentAndGetERKNS_12CacheKeyBaseERPKNS_12SharedObjectER10UErrorCode+0x1c9): undefined reference to `std::__throw_system_error(int)'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: /opt/static-php-cli/buildroot/lib/libicui18n.a(numparse_validators.ao):(.rodata._ZTIN6icu_738numparse4impl21RequireAffixValidatorE[_ZTIN6icu_738numparse4impl21RequireAffixValidatorE]+0x0): undefined reference to `vtable for __cxxabiv1::__vmi_class_type_info'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: /opt/static-php-cli/buildroot/lib/libicui18n.a(numparse_validators.ao):(.rodata._ZTIN6icu_738numparse4impl24RequireCurrencyValidatorE[_ZTIN6icu_738numparse4impl24RequireCurrencyValidatorE]+0x0): undefined reference to `vtable for __cxxabiv1::__vmi_class_type_info'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: /opt/static-php-cli/buildroot/lib/libicui18n.a(numparse_validators.ao):(.rodata._ZTIN6icu_738numparse4impl32RequireDecimalSeparatorValidatorE[_ZTIN6icu_738numparse4impl32RequireDecimalSeparatorValidatorE]+0x0): undefined reference to `vtable for __cxxabiv1::__vmi_class_type_info'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: /opt/static-php-cli/buildroot/lib/libicui18n.a(numparse_validators.ao):(.rodata._ZTIN6icu_738numparse4impl22RequireNumberValidatorE[_ZTIN6icu_738numparse4impl22RequireNumberValidatorE]+0x0): undefined reference to `vtable for __cxxabiv1::__vmi_class_type_info'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: /opt/static-php-cli/buildroot/lib/libicui18n.a(numparse_validators.ao):(.rodata._ZTIN6icu_738numparse4impl22MultiplierParseHandlerE[_ZTIN6icu_738numparse4impl22MultiplierParseHandlerE]+0x0): undefined reference to `vtable for __cxxabiv1::__vmi_class_type_info'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: /opt/static-php-cli/buildroot/lib/libicuuc.a(umutex.ao): in function `std::call_once<void (&)()>(std::once_flag&, void (&)())::{lambda()#2}::_FUN()':
umutex.cpp:(.text._ZZSt9call_onceIRFvvEJEEvRSt9once_flagOT_DpOT0_ENUlvE0_4_FUNEv[_ZZSt9call_onceIRFvvEJEEvRSt9once_flagOT_DpOT0_ENUlvE0_4_FUNEv]+0x3): undefined reference to `std::__once_callable'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: /opt/static-php-cli/buildroot/lib/libicuuc.a(umutex.ao): in function `umtx_init':
umutex.cpp:(.text.umtx_init+0x32): undefined reference to `std::condition_variable::condition_variable()'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: /opt/static-php-cli/buildroot/lib/libicuuc.a(umutex.ao): in function `umtx_cleanup':
umutex.cpp:(.text.umtx_cleanup+0xc): undefined reference to `std::condition_variable::~condition_variable()'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: /opt/static-php-cli/buildroot/lib/libicuuc.a(umutex.ao): in function `icu_73::UMutex::getMutex()':
umutex.cpp:(.text._ZN6icu_736UMutex8getMutexEv+0x23): undefined reference to `std::__once_callable'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: umutex.cpp:(.text._ZN6icu_736UMutex8getMutexEv+0x30): undefined reference to `__once_proxy'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: umutex.cpp:(.text._ZN6icu_736UMutex8getMutexEv+0x4b): undefined reference to `std::__once_call'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: umutex.cpp:(.text._ZN6icu_736UMutex8getMutexEv+0xd0): undefined reference to `std::__throw_system_error(int)'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: /opt/static-php-cli/buildroot/lib/libicuuc.a(umutex.ao): in function `umtx_lock_73':
umutex.cpp:(.text.umtx_lock_73+0x3a): undefined reference to `std::__throw_system_error(int)'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: /opt/static-php-cli/buildroot/lib/libicuuc.a(umutex.ao): in function `icu_73::umtx_initImplPreInit(icu_73::UInitOnce&)':
umutex.cpp:(.text._ZN6icu_7320umtx_initImplPreInitERNS_9UInitOnceE+0x3): undefined reference to `__once_proxy'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: umutex.cpp:(.text._ZN6icu_7320umtx_initImplPreInitERNS_9UInitOnceE+0x12): undefined reference to `std::__once_callable'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: umutex.cpp:(.text._ZN6icu_7320umtx_initImplPreInitERNS_9UInitOnceE+0x2c): undefined reference to `std::__once_call'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: umutex.cpp:(.text._ZN6icu_7320umtx_initImplPreInitERNS_9UInitOnceE+0x7b): undefined reference to `std::condition_variable::wait(std::unique_lock<std::mutex>&)'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: umutex.cpp:(.text._ZN6icu_7320umtx_initImplPreInitERNS_9UInitOnceE+0xcf): undefined reference to `std::__throw_system_error(int)'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: umutex.cpp:(.text._ZN6icu_7320umtx_initImplPreInitERNS_9UInitOnceE+0xd9): undefined reference to `std::__throw_system_error(int)'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: /opt/static-php-cli/buildroot/lib/libicuuc.a(umutex.ao): in function `icu_73::umtx_initImplPostInit(icu_73::UInitOnce&)':
umutex.cpp:(.text._ZN6icu_7321umtx_initImplPostInitERNS_9UInitOnceE+0x47): undefined reference to `std::__throw_system_error(int)'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: umutex.cpp:(.text._ZN6icu_7321umtx_initImplPostInitERNS_9UInitOnceE+0x4e): undefined reference to `std::__throw_system_error(int)'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: umutex.cpp:(.text._ZN6icu_7321umtx_initImplPostInitERNS_9UInitOnceE+0x3d): undefined reference to `std::condition_variable::notify_all()'
/usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: /opt/static-php-cli/buildroot/lib/libicuuc.a(unifilt.ao):(.rodata._ZTIN6icu_7313UnicodeFilterE[_ZTIN6icu_7313UnicodeFilterE]+0x0): undefined reference to `vtable for __cxxabiv1::__vmi_class_type_info'
collect2: error: ld returned 1 exit status

Moving -lstdc++ to the end fixes it.

@DubbleClick
Copy link
Contributor Author

It's php's fault...

Building php embed with extra-libs: /opt/static-php-cli/buildroot/lib/libicui18n.a /opt/static-php-cli/buildroot/lib/libicuio.a /opt/static-php-cli/buildroot/lib/libicuuc.a /opt/static-php-cli/buildroot/lib/libicudata.a /opt/static-php-cli/buildroot/lib/libssl.a /opt/static-php-cli/buildroot/lib/libcrypto.a /opt/static-php-cli/buildroot/lib/libz.a -lstdc++

creates libs=" -lstdc++ -lrt -lm -ldl -lpthread -lssl -lcrypto -lz -licuio -licui18n -licuuc -licudata " in php-config.

@DubbleClick
Copy link
Contributor Author

Mystery solved, I guess. It's really just the order of the includes that are somehow wrong in so many places. -licudata comes before -licuu18n by default, which causes link errors. -lstdc++ comes first in php-config, -lz is just missing from openssl.pc despite being required. Trying to build php with all extensions statically is a mess I did not expect.

Now to figure out why -buildmode=pie works on alpine, but not on glibc based operating systems, even when I build musl-cross-compile with -fPIE.

@DubbleClick
Copy link
Contributor Author

For what it's worth, I found that php 8.2 works with opcache without disabling JIT.

@dunglas
Copy link
Owner

dunglas commented Oct 4, 2023

@DubbleClick do you think you can open a PR upstream for that?

@DubbleClick
Copy link
Contributor Author

I've fixed it in #203, but the PR does a little bit of everything and I should probably split it up into different PRs.

The --with-libs option also needs a few fixes before it works in SPC, but it's essential to get jpeg/webp support in gd or imagick

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

No branches or pull requests

2 participants