Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .nanvix/runtime_sos.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,18 @@
# _ssl.cpython-312.so -> libssl.so + libcrypto.so
# libssl.so -> libcrypto.so
# _hashlib.cpython-312.so -> libcrypto.so
# _bz2.cpython-312.so -> libbz2.so
# _lzma.cpython-312.so -> liblzma.so
# zlib.cpython-312.so -> libz.so
# _sqlite3.cpython-312.so -> libsqlite3.so
REQUIRED_RUNTIME_SOS: tuple[str, ...] = (
"libffi.so",
"libcrypto.so",
"libssl.so",
"libbz2.so",
"liblzma.so",
"libz.so",
"libsqlite3.so",
)


Expand Down
42 changes: 28 additions & 14 deletions .nanvix/setup_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,25 +277,21 @@ class SetupEntry(NamedTuple):
SetupEntry(name="termios", linkage=Linkage.SHARED, tokens=("termios.c",)),
# ---------------- Modules with external Nanvix-ported deps ---------
#
# libffi, libssl, libcrypto each ship as a .so under $(SYSROOT)/lib/
# and the consuming extension .so (_ctypes, _ssl, _hashlib)
# references it via DT_NEEDED. The loader resolves them at dlopen
# time and binds UND symbols against python.elf .dynsym.
#
# _bz2 / _lzma / zlib / _sqlite3 are intentionally NOT moved here:
# the Nanvix port repos for libbz2 / liblzma / libz / libsqlite3 do
# not yet ship .so builds, so those four extensions stay statically
# built into python.elf (cpython upstream default) until the
# follow-up PR that lands alongside the Wave 6 port-repo .so PRs.
# libffi / libssl / libcrypto / libbz2 / liblzma / libz / libsqlite3
# each ship as a .so under $(SYSROOT)/lib/ and the consuming
# extension .so emits DT_NEEDED for it; the Nanvix dynamic loader
# walks the chain at dlopen time and binds UND symbols against
# python.elf .dynsym. This matches the upstream cpython behavior
# when configure is invoked with system-library detection enabled
# (the default on every Linux distro).
SetupEntry(
name="_ssl",
linkage=Linkage.SHARED,
tokens=("_ssl.c",),
section_header=(
"Stdlib modules with external Nanvix-ported deps that are "
"already shipped as .so by their respective port repos. "
"Each .so emits DT_NEEDED for the corresponding sysroot "
"library; the loader walks the chain at dlopen time."
"Stdlib modules with external Nanvix-ported deps. Each .so "
"emits DT_NEEDED for the corresponding sysroot library; the "
"loader walks the chain at dlopen time."
),
),
SetupEntry(name="_hashlib", linkage=Linkage.SHARED, tokens=("_hashopenssl.c",)),
Expand All @@ -310,6 +306,24 @@ class SetupEntry(NamedTuple):
"_ctypes/cfield.c",
),
),
SetupEntry(name="_bz2", linkage=Linkage.SHARED, tokens=("_bz2module.c",)),
SetupEntry(name="_lzma", linkage=Linkage.SHARED, tokens=("_lzmamodule.c",)),
SetupEntry(name="zlib", linkage=Linkage.SHARED, tokens=("zlibmodule.c",)),
SetupEntry(
name="_sqlite3",
linkage=Linkage.SHARED,
tokens=(
"_sqlite/blob.c",
"_sqlite/connection.c",
"_sqlite/cursor.c",
"_sqlite/microprotocols.c",
"_sqlite/module.c",
"_sqlite/prepare_protocol.c",
"_sqlite/row.c",
"_sqlite/statement.c",
"_sqlite/util.c",
),
),
)


Expand Down
5 changes: 5 additions & 0 deletions .nanvix/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@
("_ssl", "hasattr(m, 'RAND_bytes')"),
("_hashlib", "hasattr(m, 'openssl_sha256') or hasattr(m, 'new')"),
("_ctypes", "hasattr(m, 'dlopen')"),
# libbz2 / liblzma / libz / libsqlite3: same DT_NEEDED model.
("_bz2", "m.BZ2Compressor().compress(b'hello') is not None"),
("_lzma", "hasattr(m, 'LZMACompressor')"),
("zlib", "m.crc32(b'hello') == 0x3610a686"),
("_sqlite3", "hasattr(m, 'connect')"),
),
),
)
Expand Down
8 changes: 4 additions & 4 deletions .nanvix/z.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@

# Map dependency names to the library files they install into buildroot/lib.
_DEP_EXPECTED_LIBS: dict[str, list[str]] = {
"bzip2": ["libbz2.a"],
"bzip2": ["libbz2.a", "libbz2.so"],
"libffi": ["libffi.a", "libffi.so"],
"zlib": ["libz.a"],
"sqlite": ["libsqlite3.a"],
"zlib": ["libz.a", "libz.so"],
"sqlite": ["libsqlite3.a", "libsqlite3.so"],
"openssl": ["libssl.a", "libcrypto.a", "libssl.so", "libcrypto.so"],
"libxml2": ["libxml2.a"],
"libxslt": ["libxslt.a", "libexslt.a"],
"lxml": ["liblxml_etree.a", "liblxml_elementpath.a"],
"xz": ["liblzma.a"],
"xz": ["liblzma.a", "liblzma.so"],
}


Expand Down
25 changes: 13 additions & 12 deletions Makefile.nanvix
Original file line number Diff line number Diff line change
Expand Up @@ -185,17 +185,18 @@ endif
# which libnvx_crt0 is the sole provider. Listing it first today keeps
# python.elf using a consistent `_start` source across both states.
#
# `LIBS` segment 2 (`--start-group ... --end-group`): the external
# Nanvix-ported libraries (`-lsqlite3 -lz -lbz2 -llzma`) whose .a files
# stay statically linked into python.elf. The corresponding extensions
# (_sqlite3, zlib, _bz2, _lzma) remain *static* in Setup.local for now
# because the Nanvix port repos for libbz2 / libz / liblzma /
# libsqlite3 do not yet ship .so builds. The follow-up cpython PR that
# lands alongside the Wave 6 port-repo .so PRs migrates these four
# extensions to *shared* with DT_NEEDED references to lib*.so. -lssl
# / -lcrypto / -lffi are NOT in this list -- they ship as separate .so
# files under sysroot/lib/ and are referenced via DT_NEEDED by their
# consumer .so modules (_ssl, _hashlib, _ctypes).
# `LIBS` segment 2 (empty after the Wave 7 unbundling): with libffi /
# libssl / libcrypto / libsqlite3 / libz / libbz2 / liblzma all
# shipped as .so under sysroot/lib/, python.elf no longer bundles any
# external Nanvix-ported libraries. The per-module .so wrappers
# (_ssl, _hashlib, _ctypes, _sqlite3, zlib, _bz2, _lzma) reference
# the corresponding system .so via DT_NEEDED; the Nanvix dynamic
# loader walks the chain at dlopen time and binds UND symbols against
# python.elf .dynsym. The per-module *_LIBS environment variables
# (LIBSQLITE3_LIBS, ZLIB_LIBS, BZIP2_LIBS, LIBLZMA_LIBS, LIBFFI_LIBS)
# in -L/-l form make ld emit the DT_NEEDED entry rather than
# embedding the .a -- exactly the upstream cpython behavior for
# system-library builds (Linux distro default).
CONFIGURE_ENV = \
CC="$(TOOLCHAIN_PREFIX)/bin/i686-nanvix-gcc" \
CXX="$(TOOLCHAIN_PREFIX)/bin/i686-nanvix-g++" \
Expand All @@ -205,7 +206,7 @@ CONFIGURE_ENV = \
CFLAGS="-O3 -fomit-frame-pointer -fno-unwind-tables -fno-asynchronous-unwind-tables -I$(SYSROOT_PATH)/include" \
CFLAGS_NODIST="-fno-semantic-interposition" \
LDFLAGS="-L$(SYSROOT_PATH)/lib -T$(SYSROOT_PATH)/lib/user.ld -Wl,--allow-multiple-definition -no-pie -Wl,--export-dynamic -Wl,--no-dynamic-linker" \
LIBS="-Wl,--whole-archive $(LIBNVX_CRT0) $(LIBPOSIX) $(LIBC) $(LIBM) $(LIBSTDCXX) $(LIBGCC) -Wl,--no-whole-archive -Wl,--start-group -lsqlite3 -lz -lbz2 -llzma -Wl,--end-group" \
LIBS="-Wl,--whole-archive $(LIBNVX_CRT0) $(LIBPOSIX) $(LIBC) $(LIBM) $(LIBSTDCXX) $(LIBGCC) -Wl,--no-whole-archive" \
LIBSQLITE3_LIBS="-L$(SYSROOT_PATH)/lib -lsqlite3" \
LIBSQLITE3_CFLAGS="-I$(SYSROOT_PATH)/include" \
ZLIB_LIBS="-L$(SYSROOT_PATH)/lib -lz" \
Expand Down