ci: fail the build when cassandra.so has undeclared native dependencies - #142
Open
CodeLieutenant wants to merge 1 commit into
Open
ci: fail the build when cassandra.so has undeclared native dependencies#142CodeLieutenant wants to merge 1 commit into
CodeLieutenant wants to merge 1 commit into
Conversation
gh-117 reported "Error relocating cassandra.so: __gmpz_cmp_ui: symbol not found" on Alpine. The module referenced libgmp's mpz_* symbols without listing libgmp in DT_NEEDED. That linkage bug is already gone on trunk, but nothing in CI could have caught it, and nothing stops it recurring. It is invisible to the obvious check because PHP dlopen()s extensions with RTLD_LAZY|RTLD_GLOBAL: * glibc binds lazily, so an unresolved symbol is deferred until first call — `php -d extension=cassandra -m` prints "cassandra" and exits 0 on a module that will die the moment a Varint is constructed. * RTLD_GLOBAL means any earlier-loaded extension donates its symbols to us, so an ext/gmp that php.ini happened to load first silently supplied them. This is why renaming cassandra.ini to sort after gmp.ini "fixed" it for the reporter. * musl has no lazy binding, so the identical file fails outright at dlopen. Hence Alpine-only reports while CI stayed green. Add scripts/check-module-symbols.sh: every undefined symbol in the built module must be provided by a library the module itself declares, or by the PHP binary. It consults nothing about the ambient process, so ini load order and the host's own libraries cannot mask a missing dependency — verified to still catch the fault on a host whose php binary links libgmp, where a load-based check passes. Wire it into verify-extension along with an isolated load (-n, no php.ini, LD_BIND_NOW=1) which covers failures a symbol audit cannot, such as a broken MINIT. Run the target from the shared build action and inline in the PIE job, which does not go through CMake. Skipped under ASan, which needs its runtime LD_PRELOADed, and on macOS, which links extensions with -undefined dynamic_lookup. Verified both directions on Alpine 3.21/musl and Debian 13/glibc 2.41: the current tree passes, and unlinking LibGMP::LibGMP fails the build.
|
Tick the box to add this pull request to the merge queue (same as
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #117.
What was reported
Unable to load dynamic library 'cassandra.so' (Error relocating cassandra.so: __gmpz_cmp_ui: symbol not found)on Alpine. The reporter worked around it by renamingcassandra.iniso it sorted aftergmp.ini.Diagnosis
The module referenced libgmp's
mpz_*symbols with nolibgmpentry inDT_NEEDED. On thev1.3.xbranch the reporter built,cmake/FindLibGMP.cmakeattached gmp toext_scylladbas a side effect offind_package, before the sub-libraries that use it existed.That linkage bug is already gone on trunk — a build on Alpine 3.21 shows
NEEDED libgmp.so.10, loads withphp -n(ext/gmp never loaded), and round-tripsVarint/Decimalcorrectly. This PR does not change the linking. It adds the guard, because nothing in CI could have caught the original bug and nothing stops it recurring.Why CI could not catch it
PHP dlopens extensions with
RTLD_LAZY|RTLD_GLOBAL(Zend/zend_portability.h):php -d extension=cassandra -mprintscassandraand exits 0 on a module that dies the moment aVarintis constructed.RTLD_GLOBAL— any earlier-loaded extension donates its symbols, so anext/gmpthat php.ini loaded first silently supplied them. That is exactly why the reporter's ini rename "fixed" it, and it is proof theNEEDEDentry was absent.dlopen. Hence Alpine-only reports while CI stayed green on Ubuntu.The guard
scripts/check-module-symbols.sh: every undefined symbol in the built module must be provided by a library the module itself declares, or by the PHP binary. It consults nothing about the ambient process, so ini load order and the host's own libraries cannot mask a missing dependency.That independence is load-bearing, not theoretical. My first attempt was
LD_BIND_NOW=1 php -nalone; it passes on a broken module on Debian 13, because thephpbinary there links libgmp itself and satisfies the symbols from the process's global scope. The isolated load is kept as a second check since it catches things a symbol audit cannot (e.g. a broken MINIT), but it is not the guard.Wired into
verify-extension, run from the shared build action and inline in the PIE job (which does not go through CMake). Skipped under ASan, which needs its runtimeLD_PRELOADed, and on macOS, which links extensions with-undefined dynamic_lookup.Verification
Built in Docker both ways — as-is, and with
LibGMP::LibGMPunlinked to re-create the fault:LibGMP::LibGMPunlinkedIn the failure case the linker accepts the broken
.soandphp -d extension=... -mstill reports success on both libcs — the audit is what fails it.Also: shellcheck clean, both YAML files parse, and removing the script makes the target fail rather than silently pass.
Note for reviewers
Considered and deliberately not included: an Alpine/musl CI job. It would add real coverage for musl-specific compile breakage, but it would not reliably catch this bug — with php.ini loaded,
gmp.soresolves the symbols on Alpine too, as the table's middle column shows. That is a separate CI-time tradeoff worth deciding on its own merits.