[build] E: Build libxml2.so alongside libxml2.a#73
Open
esaurez wants to merge 1 commit into
Open
Conversation
Produce a position-independent libxml2.so in addition to the existing static libxml2.a. The .so embeds zlib via --whole-archive so it is self-contained, and leaves libposix/libc/libm symbols unresolved so they bind to the host executable's .dynsym at dlopen time (matching the extension-module model already used by Nanvix guest binaries that dlopen .so plugins). Concretely: * `--enable-static --disable-shared` stays in configure (libtool's shared-library detection has no rules for i686-nanvix); `-fPIC` is added to CFLAGS so the same .o files are usable for both archives. * A new `.libs/libxml2.so` target links the .so manually from libxml2.a + libz.a via `-shared -fPIC -nostdlib`, setting DT_SONAME=libxml2.so so downstream consumers emit the correct DT_NEEDED entry. * `test-functional` now sanity-checks the .so: presence, minimum size, DT_SONAME, and that the public libxml2 entry points (xmlInitParser, xmlParseMemory) appear in .dynsym. * `package` / `verify-package` ship both libxml2.a and libxml2.so. Runtime dependency: this shared-library build only becomes useful once the loader changes in nanvix/nanvix#2473 ([syscall] E: Run dlopen ctors/dtors and DT_RUNPATH) ship, because most C/C++ libraries -- including libxml2's transitive consumers like libxslt and Python bindings -- rely on `.init_array` constructors that the current loader silently skips. The libxml2 unit-test in this PR does not exercise that path; downstream `.so` consumers will. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR updates the Nanvix port build to produce a shared libxml2.so alongside the existing static libxml2.a, and to include the .so in build outputs and release staging.
Changes:
- Add a
libxml2.sobuild target that links fromlibxml2.apluslibz.awith PIC and a fixed SONAME. - Extend functional tests to sanity-check the produced
.so(SONAME and exported symbols). - Update the Nanvix
z.pybuild script to treatlibxml2.soas a build/release artifact.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
.nanvix/z.py |
Adds libxml2.so to Docker-copied build outputs and to the staged outputs list for release. |
.nanvix/Makefile.nanvix |
Adds a shared-library link step and .so checks in tests; adds package/verify targets; changes build/staging flow. |
Comments suppressed due to low confidence (1)
.nanvix/z.py:79
Libxml2Build.docker_config()will always try to copy back the install-staged outputs returned by_staged_output_files()(e.g.,lib_out()/libxml2.a,bin_out()/xml2-config, etc.). However, the updated Makefile no longer has aninstall/staging step in thealltarget, so these paths will not be created during./z buildand the Docker output-copy step is likely to fail (or./z releasewill miss artifacts). Either restore a staging step in.nanvix/Makefile.nanvix(preferred, since the comments here assume it), or update this script to copy/package artifacts from their new locations (e.g., thepackagetarget’s tarball).
def _staged_output_files(self) -> list[str]:
"""Return install-staged artifact paths (relative to repo_root())
so Windows tar-copy mode also copies them back to the host.
"""
root = repo_root()
return [
str((lib_out() / "libxml2.a").relative_to(root)),
str((lib_out() / "libxml2.so").relative_to(root)),
str(
(include_out() / "libxml2" / "libxml" / "xmlversion.h").relative_to(
root
)
),
str((bin_out() / "xml2-config").relative_to(root)),
str((test_out() / "test_libxml2.elf").relative_to(root)),
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Summary
Produce a position-independent
libxml2.soin addition to the existing staticlibxml2.a. The shared library embedszlibvia--whole-archiveso it is self-contained, and leaveslibposix/libc/libmsymbols unresolved so they bind to the host executable's.dynsymat dlopen time -- matching the extension-module model used elsewhere on Nanvix.What changes
.nanvix/Makefile.nanvix$(SHAREDLIB)target (.libs/libxml2.so) that links manually fromlibxml2.a+libz.avia-shared -fPIC -nostdlib, setsDT_SONAME=libxml2.soso downstream consumers emit the rightDT_NEEDEDentry.test-functionalnow sanity-checks the.so: presence, minimum size,DT_SONAME, and that the public libxml2 entry points (xmlInitParser,xmlParseMemory) appear in.dynsym.package/verify-packageship bothlibxml2.aandlibxml2.so..nanvix/z.py.libs/libxml2.soto_BUILD_OUTPUTS(so the Docker wrapper copies the .so back to the host) and to_staged_output_files()(soreleasepackages it).Why bare SONAME (
libxml2.so, notlibxml2.so.2)Upstream libxml2 ships SONAME
libxml2.so.2. The Nanvix port uses the barelibxml2.sobecause Nanvix is currently single-vendor: every consumer of this library is also built in this monorepo against this exact version, and Nanvix has noLD_LIBRARY_PATH-style runtime version search. If a third-party consumer ever needs the versioned name, thepackagetarget can install alibxml2.so.2 -> libxml2.sosymlink as a follow-up; that change is non-load-bearing for current consumers and intentionally out of scope here.Configure invariants kept
--enable-static --disable-sharedstays in configure (libtool's shared-library detection has no rules fori686-nanvix);-fPICis added toCFLAGSso the same.ofiles are usable for both archives.Runtime dependency
The .so only becomes useful once the loader changes in nanvix/nanvix#2473 (
[syscall] E: Run dlopen ctors/dtors and DT_RUNPATH) ship, because most C/C++ libraries -- including libxml2's downstream consumers libxslt and lxml -- rely on.init_arrayconstructors that the current loader silently skips. The libxml2 unit-test in this PR does not exercise that path; downstream.soconsumers will.Validation
./z buildproduces.libs/libxml2.a(~5.7 MB) and.libs/libxml2.so(~1.5 MB).test-functionalpasses the structural checks (SONAME present, public entry points exported).