[build] E: Build liblzma.so alongside liblzma.a#97
Open
esaurez wants to merge 1 commit into
Open
Conversation
Adds a liblzma.so link step inside the existing build script that links liblzma.so from the (now PIC) static archive via -Wl,--whole-archive so every liblzma entry point becomes part of the .so's .dynsym. Sets DT_SONAME=liblzma.so so consumers that link against it emit a proper DT_NEEDED entry. liblzma is self-contained -- no transitive .so deps -- so the .so records no DT_NEEDED of its own. libc / libm symbols (memcpy, memset, malloc, ...) are left UND via -nostdlib and bind at dlopen time against the host executable's .dynsym, matching the model already used by other Nanvix shared libraries such as libffi.so / libssl.so. xz's autotools libtool does not know about i686-nanvix, so the upstream --enable-shared path is not viable. The configure opts keep --disable-shared --enable-static; the .so is linked manually from the .a after `make install` completes. Changes to .nanvix/z.py: - _configure_env_overrides: append -fPIC to CFLAGS so the same .o files compile into both .a and .so. - build: add a SHAREDLIB link step after `make install DESTDIR=...` that writes liblzma.so directly into the install staging tree alongside liblzma.a. - _stage_artefacts: extend the lib_dir / build_dir copy-out to cover liblzma.so in addition to liblzma.a. - _stage_release_outputs: copy liblzma.so into lib_out() so `./z release` packages it. Adds .gitattributes forcing LF line endings on the vendored Unix shell / autotools scripts (configure, config.*, install-sh, build-aux/*, *.sh, ...). These are already committed as LF; the attribute keeps them LF on checkout regardless of a contributor's core.autocrlf setting, so dash inside the Linux toolchain container does not choke on CRLF. This replaces an earlier runtime CR-stripping workaround that was carried in the build script. Runtime dependency: the shared-library build becomes useful once the loader changes in nanvix/nanvix#2473 ([syscall] E: Run dlopen ctors/dtors and DT_RUNPATH) ship. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Jun 17, 2026
There was a problem hiding this comment.
Pull request overview
This PR updates the Nanvix xz port build to produce a shared liblzma.so alongside the existing static liblzma.a, enabling runtime dlopen/DT_NEEDED consumption (e.g., CPython _lzma.so) instead of requiring static embedding.
Changes:
- Compile the liblzma objects with
-fPICso they can be reused for a shared library. - Manually link and stage
liblzma.sofrom the libtool-producedliblzma.a, and include it in artefact/release staging. - Add
.gitattributesrules to keep vendored autotools/shell scripts checked out with LF endings.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
.nanvix/z.py |
Adds PIC CFLAGS, links liblzma.so from the static archive post-install, and stages/copies the new .so into build and release outputs. |
.gitattributes |
Forces LF line endings for configure/autotools helper scripts to avoid CRLF issues in container builds from Windows checkouts. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # i686-nanvix (hence --disable-shared in configure opts), | ||
| # so we link the .so ourselves and stage it next to .a. | ||
| f"{shlex.quote(cc)} -shared -fPIC -nostdlib " | ||
| f" -Wl,-soname,liblzma.so -Wl,-z,noexecstack" |
Comment on lines
333
to
334
| "set -e", | ||
| configure_cmd, |
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
Builds
liblzma.soalongside the existingliblzma.aso consumers candlopenxz at run time instead of statically linking it.Why
Today the Nanvix xz port ships only
liblzma.a. Anything that wants xz (e.g., cpython's_lzmaextension) has to statically embed it into the consumer binary. That works for cpython's monolithicpython.elfbut does not allow:.soconsumers in the same process._lzma.sothat resolves xz viaDT_NEEDED liblzma.so(the model already used by_ssl.so→libssl.soand_ctypes.so→libffi.soon Nanvix).Producing
liblzma.sohere unblocks the cpython migration of_lzmafrom--whole-archive .a in python.elftoDT_NEEDED .so.What changed
xz uses autotools and the upstream
--enable-sharedpath goes throughlibtool, which does not know abouti686-nanvix. Rather than teaching libtool a new platform target, this PR keeps--disable-shared --enable-staticand linksliblzma.somanually from the.aaftermake installcompletes, the same approach already taken by nanvix/libffi#235.Concretely,
.nanvix/z.py:_configure_env_overrides: appends-fPICtoCFLAGSso the same.ofiles compile into both.aand.so.build(in-Docker shell script):\rfrom the vendored autotools scripts before running./configure. Required on Windows hosts wheregit'score.autocrlf=trueconverts shell scripts to CRLF anddashinside the container chokes on the trailing\r(no-op on Unix hosts where the files already have LF endings).gcc -sharedinvocation aftermake install DESTDIR=...that linksliblzma.sofromsrc/liblzma/.libs/liblzma.avia-Wl,--whole-archivewithDT_SONAME=liblzma.soand-nostdlib(libc / libm UND, bind at dlopen). Writes the result into<install-stage>/sysroot/lib/liblzma.so._stage_artefacts: extends thelib_dir/build_dircopy-out to coverliblzma.soin addition toliblzma.a._stage_release_outputs: copiesliblzma.sointolib_out()so./z releasepackages it.Architecture
liblzma.sohas no transitive.sodependencies (liblzma is self-contained; libc/libm symbols are UND), so the loader does not need to walk any DT_NEEDED chain to load it.Dependencies
Runtime dep (already merged upstream):
dlfcninit-array + DT_RUNPATH support. Required for any consumer todlopen("liblzma.so")at run time.Validation
Build runs end-to-end inside the toolchain-gcc Docker image on a Windows host:
Structural verification of the produced
liblzma.so:SONAME correctly set, no spurious DT_NEEDED, full
lzma_*public API exported, libc symbols left UND for runtime binding. The existingliblzma.aand the upstreamtest_*.elftest binaries continue to build unchanged.