Commit c96a209
[nanvix] E: Build _ssl/_hashlib/_ctypes + lxml extensions as .so
Builds 3 stdlib extensions (_ssl, _hashlib, _ctypes) and the 2 lxml
extensions as runtime-loaded .so files, and confirms that libffi /
libssl / libcrypto / libxml2 / libxslt / libexslt / lxml ship as
standalone .so files referenced via DT_NEEDED.
This matches upstream cpython's default behavior on every Linux
distro (system-library detection enabled): cpython's normal
MODULE_*_LDFLAGS machinery wires each extension's per-module
*_LIBS env var ("-L/-l" form) into its .so link line, producing a
proper DT_NEEDED entry rather than embedding the .a.
Modules covered
---------------
- _ssl.cpython-312.so -> DT_NEEDED libssl.so -> libcrypto.so
- _hashlib.cpython-312.so -> DT_NEEDED libcrypto.so
- _ctypes.cpython-312.so -> DT_NEEDED libffi.so
- _lxml_etree.cpython-312.so + _lxml_elementpath.cpython-312.so:
thin dlopen shims (see lxml shim layer note below).
python.elf LIBS drops -lssl -lcrypto -lffi (those symbols come from
the standalone .so files now). _ssl and _hashlib previously embedded
their own copies of libcrypto.a (~5.5 MB each); the deduplication
ends the OpenSSL init-order bug where the two copies maintained
separate provider state and the first openssl_sha256() call failed.
Out of scope: _bz2 / _lzma / zlib / _sqlite3. Their Nanvix port
repos do not yet ship .so builds (the Wave 6 port-repo PRs add
those), so those four extensions stay statically linked into
python.elf for now -- the same shape upstream cpython produces
without --with-system-* flags. The follow-up cpython PR migrates
them once Wave 6 lands.
lxml shim layer
---------------
The lxml port repo (nanvix/lxml) currently emits Cython outputs as
system shared libraries (/lib/liblxml_*.so) rather than as native
cpython extension modules (site-packages/lxml/etree.cpython-312-*.so,
the upstream pip-installed layout). Until the port is fixed,
Modules/lxml_etree_builtin.c and Modules/lxml_elementpath_builtin.c
remain in place as thin dlopen shims (via the new
Modules/lxml_dlopen_shim.h helper) that load the system libraries
at runtime and forward the cpython PyInit_* symbol.
The handle is intentionally leaked on success because lxml.etree
owns process-lifetime parser state -- unloading would invalidate
live xmlNodePtr values in the Python heap. RTLD_GLOBAL lets a
hypothetical future libxml2/libxslt consumer (e.g., xmlsec) resolve
its references against the symbols this dlopen publishes.
This shim layer is a Nanvix-specific stopgap; once the lxml port
emits native cpython extensions, the entire shim layer goes away
and cpython's standard importer loads lxml.etree directly. Tracked
in nanvix-todo/lxml-port-ship-as-native-cpython-extensions.md.
Mechanics
---------
- .nanvix/setup_local.py: adds 3 *shared* entries (_ssl, _hashlib,
_ctypes); flips _lxml_etree / _lxml_elementpath from a
static-link form to bare-source entries (the shim now dlopens
the .so chain at runtime).
- .nanvix/config.py: drops -lssl -lcrypto -lffi from python.elf LIBS.
- Makefile.nanvix: LIBS drops -lssl -lcrypto -lffi. Per-module
*_LIBS env vars (LIBSQLITE3_LIBS, ZLIB_LIBS, BZIP2_LIBS,
LIBLZMA_LIBS, LIBFFI_LIBS) stay in -L/-l form -- same as upstream
cpython's system-library detection produces.
- .nanvix/runtime_sos.py (new): REQUIRED_RUNTIME_SOS + helper to
stage the 8 .so files (libxml2, libxslt, libexslt, liblxml_etree,
liblxml_elementpath, libffi, libcrypto, libssl) from buildroot/lib/
into sysroot/lib/, with fail-fast FileNotFoundError on a missing
dep. Consumed by both .nanvix/test.py and .nanvix/package.py.
- .nanvix/test.py: adds one row to _SO_MODULE_SANITY_CHECKS for
_ssl / _hashlib / _ctypes.
- .nanvix/z.py: _DEP_EXPECTED_LIBS["libffi"] adds libffi.so;
_DEP_EXPECTED_LIBS["openssl"] adds libssl.so + libcrypto.so.
- Modules/lxml_dlopen_shim.h (new): shared dlopen helper used by
both lxml shim .c files.
- Modules/lxml_etree_builtin.c and lxml_elementpath_builtin.c:
each shrinks to ~10 lines wrapping a single lxml_dlopen_shim() call.
Runtime dependencies
--------------------
- nanvix/nanvix#2472 -- libm visibility fix (inherited from PR-A).
- nanvix/nanvix#2473 -- dlfcn init-array + DT_RUNPATH support.
Two additional Nanvix loader fixes are required for this PR to
function at run time and must land upstream before this PR is
mergeable:
- A loader fix for diamond DT_NEEDED chains so libcrypto.so reached
via libssl.so and directly from _hashlib.cpython-312.so resolves
to a single mapped instance.
- A pthread_once fix in libposix so OpenSSL's lazy provider init
does not hang on first call.
Companion port-lib repos: the Nanvix port libraries must be the
versions that produce the corresponding .so files (libffi, openssl,
libxml2, libxslt, lxml). Already pinned in cpython's nanvix.toml
and consumed via the buildroot snapshot.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 10289fb commit c96a209
10 files changed
Lines changed: 253 additions & 42 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
112 | | - | |
| 112 | + | |
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
166 | 167 | | |
167 | 168 | | |
168 | 169 | | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
169 | 180 | | |
170 | 181 | | |
171 | 182 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
94 | 99 | | |
95 | 100 | | |
96 | 101 | | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
105 | 110 | | |
106 | | - | |
107 | 111 | | |
108 | 112 | | |
109 | 113 | | |
110 | 114 | | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
| 115 | + | |
118 | 116 | | |
119 | 117 | | |
120 | 118 | | |
| |||
275 | 273 | | |
276 | 274 | | |
277 | 275 | | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
278 | 311 | | |
279 | 312 | | |
280 | 313 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| |||
105 | 106 | | |
106 | 107 | | |
107 | 108 | | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
108 | 119 | | |
109 | 120 | | |
110 | 121 | | |
| |||
522 | 533 | | |
523 | 534 | | |
524 | 535 | | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
525 | 546 | | |
526 | 547 | | |
527 | 548 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
83 | | - | |
| 83 | + | |
84 | 84 | | |
85 | 85 | | |
86 | | - | |
| 86 | + | |
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
185 | 185 | | |
186 | 186 | | |
187 | 187 | | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
193 | 199 | | |
194 | 200 | | |
195 | 201 | | |
| |||
199 | 205 | | |
200 | 206 | | |
201 | 207 | | |
202 | | - | |
| 208 | + | |
203 | 209 | | |
204 | 210 | | |
205 | 211 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | | - | |
5 | | - | |
| 4 | + | |
6 | 5 | | |
7 | 6 | | |
8 | | - | |
| 7 | + | |
9 | 8 | | |
10 | | - | |
| 9 | + | |
11 | 10 | | |
12 | 11 | | |
13 | 12 | | |
14 | 13 | | |
15 | | - | |
| 14 | + | |
16 | 15 | | |
0 commit comments