Skip to content

process.dlopen: Bun's zlib is the last resort for the zlib imports of a node_register_module_v<ABI> addon - #47773

Draft
robobun wants to merge 1 commit into
robobun/b72bafe4/node-register-entryfrom
robobun/b72bafe4/addon-host-zlib
Draft

robobun wants to merge 1 commit into
robobun/b72bafe4/node-register-entryfrom
robobun/b72bafe4/addon-host-zlib

Conversation

@robobun

@robobun robobun commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

Part of #9785

Problem

Fix

  • For an addon loaded through node_register_module_v<ABI> on Linux with glibc, Bun fills the imports of these 13 with its own zlib: all or none.
  • It fills only when every relocation that names one is unbound and storable, and dlsym finds none of them. It stores after the import check.
  • Verified: 24 tests (test/js/node/process/dlopen-duplicate-load.test.ts, test/v8/v8.test.ts), 11 fail on the base. 15 unit tests, also with Miri.
  • Self-reviewed: 35 concerns raised, 34 addressed, 1 rejected (Notes).

Background

  • With RTLD_LAZY the loader fills an import's slot at the first call and never looks up a filled slot.
  • One z_stream must not pass through two zlib implementations, so Bun never fills a part.
  • Considered an export as in Node: each later library would bind to it. A maintainer decides (Notes).

Downsides

  • Two addon shapes that the base refuses load here and then fail (Notes).
  • A dedicated compressor takes 140,032 bytes on Bun's zlib-ng (Node: 74,288). A load scans the relocations: 616,000 instructions for uWebSockets.js. .text +2,944 bytes.
  • With uWebSockets.js loadable, a handler that runs the event loop (Bun.build with a pending setup()) can end the process until Stop running the event loop inside JavaScript calls #46545 (Notes).
Notes

One decision for a maintainer: how does an addon get zlib

The answer differs by object format. uWebSockets.js ships binaries for five targets.

Format Binaries of uWebSockets.js What can serve it
ELF with glibc linux x64, linux arm64 this private binding, or an export
Mach-O darwin x64, darwin arm64 an export only: the 13 names in src/symbols.txt
PE win32 x64 an export only: the 13 names in src/symbols.def
  • This PR is the private binding for ELF. It changes nothing outside the addon. It does not serve macOS, where uWebSocket.js package doesnt work on bun #9785 was filed, or Windows.
  • An export on ELF must be all 88 zlib names with no version, in a linker script like src/libc-functions.lds, which exports 12 libc functions that way since Compile TypeScript to machine code ahead of time: bun build --compile --aot #45631. A model of the other forms (a small host linked with Bun's link flags and Bun's zlib objects): an export of only the 13 names, or under the BUN_1.2 version, crashes the distribution's libpng16 in a PNG read. With all 88 names and no version, libpng16 and every library that links libz.so.1 bind to the host's zlib, and a caller that opens libz.so.1 by handle (as bun:ffi does) aborts in a streaming call. The nodejs.org build of Node has that last effect too.
  • "As Node does" is true of the nodejs.org build. Distribution builds configure Node with --shared-zlib: Homebrew's Linux build of Node exports 0 zlib names, and the 13 imports of the addon bind to libz.so.1.
  • The baseline without this PR: with process.dlopen: load an addon through node_register_module_v<ABI> where its imports can be checked #47666 alone, LD_PRELOAD=libz.so.1 loads the addon on the system's zlib. This PR removes that step and the need for a system zlib.
  • A third way needs no change in Bun: uWebSockets.js links a hidden static zlib into its binaries. Its Windows build already downloads the source of zlib 1.3.1. Nobody has asked upstream, and the published tags would still need one of the other two ways.
  • If the answer is an export on ELF, that list replaces the src/ changes of this PR.

Limits of this head

In each case the base refuses the addon with a catchable error, and Node v26.3.0 works.

  1. A library that the addon links imports zlib from the host too. Bun reads only the object that has the initializer. The addon loads, and the library's first zlib call ends the process with exit 127. The import check of process.dlopen: load an addon through node_register_module_v<ABI> where its imports can be checked #47666 has the same limit for every import of such a library.
  2. The addon keeps the address of a zlib function outside the 13 (for example deflateParams) in its data, and a zlib is only in the scope of another library that loaded the addon as its dependency. The loader binds that address there in dlopen(). No lookup searches that scope, and the 13 imports are calls that the loader has not bound yet, so Bun fills them. A stream of Bun's zlib then goes into the other zlib: zlib failed at deflateParams. It needs both things at once. uWebSockets.js imports only the 13.

Two ways to close the second one, neither built: take a bound relocation of any zlib API name as the proof of a zlib (that needs a list made from zlib's own export list), or ask dlsym also on the handle of every loaded object that needs the addon.

The version before this head had two more holes, which are closed. An address-taken import of one of the 13 that the loader bound to a zlib that no lookup finds, beside 12 jump slots: one stream went through two zlibs. A weak import that the addon tests before the call (if (deflate)): the addon got 12 functions and a null deflate. Both addons are now refused with the base's text, or filled as a whole.

Order

The rule

The table is the 13 functions that uWebSockets.js imports: deflate, deflateBound, deflateEnd, deflateInit2_, deflateInit_, deflateReset, deflateSetDictionary, inflate, inflateEnd, inflateInit2_, inflateInit_, inflateReset, inflateSetDictionary.

The filling is a step of its own before the import check of #47666. When Bun fills nothing, the check runs exactly as without this PR.

  1. Bun reads every relocation of the addon that stores the address of one of the 13 functions: a jump slot, a slot of the global offset table or a word of data, in the table of DT_JMPREL and in that of DT_RELA, for a strong and for a weak import. A slot that holds Bun's own function already is left out: an earlier load has filled it, or a load on another thread is filling it now. Bun fills the other slots, unless one of these holds:

    • one of them is bound to something else. The loader has then found a zlib in the addon's scope, also where no lookup finds one.
    • a word of data has an addend.
    • Bun cannot read a table, a symbol, a name or a slot.
    • dlsym finds one of the 13 names, in the global scope or in the addon's own libraries.
    • a slot is not storable.

    In each of these cases Bun fills nothing. None of them is an error.

  2. The import check runs as on the base. An import whose slot Bun fills counts as bound. With nothing to fill, an import of zlib is treated like every other import: a weak one is skipped, a strong one is asked about, and the first one that nothing defines refuses the addon by its name.

  3. If the check has found nothing, Bun stores its functions in the slots.

So nothing is stored in an addon that is refused, and Bun never fills a part of these imports. A zlib import outside the 13 is an ordinary import. With a zlib in scope the loader binds it. Without one the addon is refused by its name.

The store

  • A slot is storable if it is aligned, with 8 bytes in a PT_LOAD range that is readable and writable, and outside PT_GNU_RELRO.
  • The store is an atomic store, and only if the slot holds another value. Several Workers can load one addon at the same time. Each writer stores the same value, and other threads can be calling through the slot. The walk reads a slot with an atomic load.
  • No lock is held, and no process-wide state is added.
  • One public function, bun_exe_format::elf_imports::resolve_lazy_imports, decides, checks and stores. Every ELF target calls it. Only glibc passes a table. With an empty table it is the check of process.dlopen: load an addon through node_register_module_v<ABI> where its imports can be checked #47666.

Who gets Bun's zlib, and who does not

  • Gets it: an addon loaded through node_register_module_v<ABI>, on Linux with glibc, opened lazily, with nothing in its scope that defines one of the 13 names and with no import of the 13 that the loader has bound.
  • With a zlib in the global scope (LD_PRELOAD, db.loadExtension(), a library opened with RTLD_GLOBAL) or in the addon's own libraries, the addon runs on that zlib, as on the base. On 18 fixtures with the system's zlib in the global scope, this build gives the base's result on all 18.
  • An addon whose only zlib is in the scope of a library that loaded it as a dependency, with 13 plain calls: Bun's zlib. Node uses the other library's zlib there.
  • An addon that registers in a static constructor or through Node-API is not checked and not filled. Its first zlib call ends the process (exit 127), as on main.
  • musl and FreeBSD: the zlib import is refused like any other import that nothing defines. musl binds a pending import again at every later dlopen(), which would undo a stored slot.
  • macOS and Windows: the arm of process.dlopen: load an addon through node_register_module_v<ABI> where its imports can be checked #47666 is not compiled there.
  • An addon bound at load (-z now, LD_BIND_NOW=1) or built with -fno-plt, with nothing that defines zlib: dlopen() fails first, with the loader's own error.
  • Code that the addon runs inside dlopen() (a static constructor) runs before Bun stores anything.

What each runtime does (Linux x64, release builds. [534,385] are the sizes of a raw deflate of the test text at levels 1 and 6 from zlib 1.3.1, which is Node's and this system's. [817,425] are Bun's. "Slots" is the count of the addon's zlib slots that hold a function of another object, before and after the load.)

Case Node v26.3.0 Base (#47666) This PR
the 13 imports, nothing defines zlib [534,385] refused, deflateInit_ [817,425], slots 0 then 13
the same, a second load in the process [534,385] twice refused [817,425] twice, slots 0, 13, 13
the system's zlib in the global scope: 13 imports, with inflateCopy, with two weak ones [534,385] [534,385], slots 0 and 0 the same as the base
the same with an address-taken deflate [534,385] [534,385], slots 1 and 1 the same as the base
an address-taken import beside 12 jump slots, under a library that needs libz.so.1 [534,385] refused, deflateInit_ refused, deflateInit_, slots 1 and 1
the same library with 13 jump slots [534,385] refused, deflateInit_ [817,425], slots 0 then 13
a weak deflate that the code tests, with RELRO [534,385] refused, deflateInit_ refused, deflateInit_, slots 0 and 0
the same with -z norelro [534,385] refused, deflateInit_ [817,425], slots 0 then 13
a weak address-taken import in writable data [534,385] refused, deflateInit_ [817,425], slots 0 then 13
weak imports of two of the 13 as jump slots [534,385] refused, deflateInit_ [817,425], slots 0 then 13
an import of inflateCopy, nothing defines zlib [534,385] refused, deflateInit_ refused, inflateCopy, slots 0 and 0
a library with 12 of the 13, in the global scope or linked [534,385] refused, inflateSetDictionary refused, inflateSetDictionary, slots 0 and 0
all 13 weak, a library in the global scope with 12 of the 13 loads loads, slots 0 and 0 loads, slots 0 and 0
all 13 weak, nothing defines zlib [534,385] loads, segmentation fault at the first call [817,425], slots 0 then 13
-z now, the system's zlib in the global scope [534,385] [534,385], slots 13 and 13 the same as the base
-z now, nothing defines zlib [534,385] undefined symbol: deflateInit_ (loader) the same as the base
an addon that links the system's zlib [534,385] [534,385], slots 0 and 0 the same as the base
an addon with the shape of uWebSockets.js and a deflate response 200, deflate, the body refused, deflateInit2_ the same as Node
limit 1: a library that the addon links imports zlib too works refused loads, exit 127 at the library's first zlib call
limit 2: the address of deflateParams beside the 13, under a library that needs libz.so.1 [534,385] refused, deflateInit_ loads, zlib failed at deflateParams

End to end (Linux x64, glibc 2.41, Node v26.3.0. A local debug build of the heads of the series on Nov 4: this stack at aae9f44 with #47619 at 02c6c91, #47607 at dbfbb42, which has #47876 below it, and #46585 merged in. The real prebuilt addon, with no shim in front of it.)

  • The program of uWebSocket.js package doesnt work on bun #9785 prints 200 Hello uWS, for the head of the addon's binaries branch and for its tag v20.71.0.
  • A script of 19 scenarios prints 24 lines. 23 are equal to Node's. The other is the order of the request headers that Bun's fetch sends.
  • The addon in a Worker (2 scripts), and four handler shapes (a plain response, a response after a settled await, a read of the request after it, a throw under an uncaughtException listener): the same output as Node.
  • 19 scripts with one feature each (POST bodies through onData, onDataV2 and collectBody, res.end with an ArrayBuffer and a Uint8Array, tryEnd, getRemoteAddress, six WebSocket cases with open, echo, send, options, upgrade data and publish, listen with a string port): 19 print what Node prints. One of them times out on both.
  • The hand-off of examples/WorkerThreads.mjs (an acceptor app gives a socket to an app on a Worker): the same two lines as Node. Node then aborts at process.exit() (uv loop ... has open handles), Bun exits 0.
  • A handler that runs the event loop inside a call: see "Order".
  • The prebuilt Linux binaries of uWebSockets.js need glibc 2.38 or later. That floor is the addon's, and Node has it too.
  • No other platform has loaded the addon.

Tests

  • test/js/node/process/dlopen-duplicate-load.test.ts, describe "an addon with only this entry that imports zlib": 23 tests, one of them for musl. A helper holds the addon with bun:ffi and counts its zlib slots that hold a function of another object, before and after process.dlopen. test/v8/v8.test.ts: "serves a response that the addon deflates with the host's zlib, like in Node".
  • With the src/ of the base (process.dlopen: load an addon through node_register_module_v<ABI> where its imports can be checked #47666), 10 of the 22 that run on glibc fail, and the deflate response fails. The other 12 pin that Bun changes nothing where it fills nothing.
  • With the src/ of the version before this head, 11 fail: the two holes that are closed (both loaded and then failed), the weak address in writable data (a crash), all 13 weak beside a partial library (refused), and the tests that expect the new refusal text.
  • Linux x64, debug build with ASAN: 62 pass, 2 skip, 0 fail in the first file. 107 pass, 1 skip, 0 fail in test/v8/v8.test.ts. cargo test -p bun_exe_format: 316 pass, 61 of them in the reader.
  • Miri runs the reader's unit tests (scripts/rust-miri.ts): 59 pass, 2 ignored. Its two-thread test fails under Miri when the store is a plain write or the read of a slot a plain read.
  • Eleven clauses of the rule were changed in turn. Each change fails a unit test, and ten of them fail an integration test too. The exception: the skip of a slot that already holds Bun's function is seen only by a unit test.
  • BUN_JSC_validateExceptionChecks=1 on the first file: no report.
  • The tests that need the system's libz.so.1 are skipped without it.

Measurements (Linux x64, release builds of this head and of the head of #47666)

  • Size: .text +2,944 bytes, all sections +2,944. Dynamic names: 704 defined and 394 undefined before and after, none of them a zlib name.
  • dlsym calls of a first and of a second process.dlopen in one process, counted in gdb:
Addon Base (#47666) This PR
13 zlib imports, nothing defines zlib 4, refused 54, then 21
the same with LD_PRELOAD=libz.so.1 41, then 34 42, then 35
an addon with the shape of uWebSockets.js and a deflate response 4, refused 87, then 48
the same with LD_PRELOAD=libz.so.1 65, then 52 66, then 53
the same addon without zlib 61, then 48 61, then 48
linked with -z now 2, then 2 2, then 2
  • An addon without a relocation that names one of the 13 makes the same calls as on the base. With a zlib in the global scope the question costs one call: the first name has a definition. With nothing that defines zlib it costs 26.
  • User-mode instructions of one process.dlopen (a hardware counter, first and second load):
Addon Base (#47666) This PR The scan adds
the uWebSockets.js-shaped test addon, 64 relocations, no zlib import 2,185,730, then 101,778 2,194,316, then 110,687 about 8,900 each load
an addon with 11 relocations, -z now 33,746, then 16,151 36,075, then 18,233 about 2,200
uWebSockets.js v20.71.0, 11,169 relocations (refused on both builds here, at its sixth question) 2,521,789, then 26,896 3,138,587, then 643,101 about 616,000 each load
  • The scan reads the name of every undefined symbol that a jump slot, a slot of the global offset table or a word of data names. That is the cost for the large addon.
  • Memory that one deflate stream allocates, from a probe addon:
Stream Node v26.3.0 Bun's zlib-ng zlib 1.3.1 (LD_PRELOAD=libz.so.1)
windowBits 9, memLevel 1 (the dedicated compressor of uWebSockets.js) 74,288 140,032 9,024
windowBits 15, memLevel 8 284,592 350,336 268,096

Self-review

35 concerns raised on the first version of this PR. 34 are addressed:

  • The rule was replaced twice. The first version stored into jump slots that the loader would have bound to a zlib of the global scope, so an addon with an address-taken deflate and LD_PRELOAD=libz.so.1 got Z_STREAM_ERROR. It also crashed on weak imports, and its list of the 88 zlib names was a hand copy that was 7 names short. The list is gone.
  • The second version decided inside the walk of the import check and read only jump slots. It had the two holes that this head closes: the decision is now a step before the check, over every relocation that names one of the 13.
  • A -z now addon is no longer skipped by its flags. The check reads the slots.
  • One public function with a caller on every target.
  • The atomic store has a test that fails without it (Miri), and "nothing is stored in a refused addon" has an integration test.
  • The test addon with the shape of uWebSockets.js moved to process.dlopen: load an addon through node_register_module_v<ABI> where its imports can be checked #47666 without its zlib use. This PR adds the deflate response.
  • The decision is asked by object format, with the measured effects of an export, the --shared-zlib builds, the LD_PRELOAD baseline and the upstream way. The memory cost and the merge order are stated.

Rejected as a change of this PR (1): a library that the addon links and that imports zlib. It needs a walk of every library of the addon, and the base has the same limit. Limit 2 above was found while this head was built, not by the review.

Other platforms

  • CI (build 137436, for a8b74c2, the same commit before a rebase on the narrowed uv: implement uv_poll_t and uv_strerror on POSIX #47524 and uv: uv_close queues the close on the loop, and close_cb runs after the check handles #47647, finished) ran both test files with 0 failures on every lane.
  • test/js/node/process/dlopen-duplicate-load.test.ts: 63 pass and 2 skip on Linux x64 and aarch64 with glibc, also with ASAN. So the filling ran on aarch64. 36 pass and 29 skip on both Alpine lanes (musl), where Bun fills nothing. 17 pass and 48 skip on Windows x64 and aarch64, 20 pass and 45 skip on macOS x64 and aarch64.
  • test/v8/v8.test.ts, which has the uWebSockets.js-shaped tests: 108 pass on Linux x64 and aarch64 with glibc, 107 pass and 1 skip with ASAN, 88 pass and 20 skip on Windows, 104 pass and 4 skip on macOS. With musl the whole file is todo, as on main.
  • Clippy, format, clang-format, the source lints and the type checks for musl, FreeBSD and aarch64 passed locally.
  • The red test files of that build are the test/aot/** family and test/bundler/compile-aot-size.test.ts, which are red on main, and test/js/web/request/request-clone-leak.test.ts on the ASAN lane, which this diff does not touch.
  • FreeBSD is type-checked only. macOS and Windows do not compile the reader.

@robobun

robobun commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator Author
Updated 12:08 PM PT - Nov 4th, 2026

❌ @robobun, your commit 32bd994 has 40 failures in Build #137603 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 47773

That installs a local version of the PR into your bun-47773 executable, so you can run:

bun-47773 --bun

@github-actions github-actions Bot added the claude label Nov 2, 2026
@robobun

robobun commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator Author

Status: draft. The head is aae9f44 (the same commit as a8b74c2, rebased on the narrowed #47524 and #47647 with no change of content), with the rule that the last status announced. Before the import check of #47666, Bun decides whether it fills the addon's imports of the 13 zlib functions: all of them or none. It fills only when every relocation that names one of them is unbound and storable and dlsym finds none of the names. It stores after the check has passed. When Bun fills nothing, the check runs as on the base.

Closed on this head: two of the three holes of the version before. An address-taken zlib import that the loader bound to a zlib that no lookup finds, and a weak import that the addon tests before the call: both addons are now refused with the base's text, or filled as a whole.

Limits that stay (the PR description has both under "Limits"): a library that the addon links and that imports zlib from the host ends the process at its first zlib call, and an addon that keeps the address of a zlib function outside the 13 under a library that has its own zlib gets one stream in two zlibs. uWebSockets.js has neither shape.

One decision for a maintainer: how an addon gets zlib from Bun. The answer differs by object format. On ELF it is this private binding, or an export of all 88 zlib names with no version. On macOS and Windows only an export can work (the 13 names in src/symbols.txt and src/symbols.def). The PR description has the measured effects of each form.

How I reproduced it: with the base's src/ (#47666), an addon that imports zlib from the host is refused: it imports 'deflateInit_', and Bun found no definition of it. On this branch it loads (Linux x64, debug build with ASAN: 63 pass and 2 skip in test/js/node/process/dlopen-duplicate-load.test.ts, 107 pass and 1 skip in test/v8/v8.test.ts).

The program of #9785: a local Linux x64 debug build of this stack (at 7ca23d0) with #47619, #47607, #47876 and #46585 merged in prints 200 Hello uWS, like Node v26.3.0, for the head of the addon's binaries branch and for its tag v20.71.0. This stack alone still refuses the addon, by the name of a V8 member that #47619 adds.

CI (build 137600, head aae9f44, finished): both test files have 0 failures on every lane. test/js/node/process/dlopen-duplicate-load.test.ts: 63 pass and 2 skip on the five lanes with glibc (x64 and aarch64, also with ASAN), 36 pass and 29 skip on both Alpine lanes (musl), 17 pass and 48 skip on Windows x64 and aarch64, 20 pass and 45 skip on macOS x64 and aarch64. test/v8/v8.test.ts passes on Linux with glibc, with ASAN and on Windows, and has 104 pass and 4 skip on macOS x64 and aarch64. On the two musl lanes that file is todo on main (#47863 removes that). test/napi/uv.test.ts passes on every POSIX lane. The red test files are the test/aot/** family and test/bundler/compile-aot-size.test.ts, which are red on main.

Stack: #47524, #47647, #47676, #47666, this PR.

@robobun
robobun force-pushed the robobun/b72bafe4/node-register-entry branch from 4246a31 to ac1eeb3 Compare November 2, 2026 20:57
@robobun
robobun force-pushed the robobun/b72bafe4/addon-host-zlib branch from d8e329f to 3011653 Compare November 2, 2026 20:57
@robobun
robobun force-pushed the robobun/b72bafe4/node-register-entry branch from ac1eeb3 to f4b61ac Compare November 2, 2026 21:25
@robobun
robobun force-pushed the robobun/b72bafe4/addon-host-zlib branch from 3011653 to 1d0c07d Compare November 2, 2026 21:25
@robobun
robobun force-pushed the robobun/b72bafe4/addon-host-zlib branch 2 times, most recently from e7f121a to 46fbfb8 Compare November 3, 2026 07:20
@robobun robobun changed the title process.dlopen: bind the zlib imports of a node_register_module_v<ABI> addon to Bun's zlib process.dlopen: Bun's zlib is the last resort for the zlib imports of a node_register_module_v<ABI> addon Nov 3, 2026
@robobun
robobun force-pushed the robobun/b72bafe4/node-register-entry branch from 65cfd3e to 9c1a9ae Compare November 3, 2026 11:20
@robobun
robobun force-pushed the robobun/b72bafe4/addon-host-zlib branch from 46fbfb8 to e1c022b Compare November 3, 2026 11:20
@robobun
robobun force-pushed the robobun/b72bafe4/addon-host-zlib branch from e1c022b to 6f9f156 Compare November 4, 2026 00:30
@robobun
robobun force-pushed the robobun/b72bafe4/node-register-entry branch from 83ff774 to 6af437e Compare November 4, 2026 03:46
@robobun
robobun force-pushed the robobun/b72bafe4/addon-host-zlib branch 2 times, most recently from 7ca23d0 to a8b74c2 Compare November 4, 2026 04:15
…ets Bun's zlib

Node's executable exports its zlib to addons. uWebSockets.js imports 13
zlib functions from it and links no libz. Bun links zlib-ng and does not
export it, so the import check refuses the addon on its first zlib
import.

With glibc, Bun now fills an addon's imports of these 13 functions with
its own functions: all of them or none. The filling is a step of its
own before the import check. When Bun fills nothing, the check runs
exactly as without this change.

1. Before the check, Bun reads every relocation of the addon that
   stores the address of one of the 13 functions: a jump slot, a slot of
   the global offset table or a word of data, in the table of DT_JMPREL
   and in that of DT_RELA, for a strong and for a weak import. A slot
   that holds Bun's own function already is left out: an earlier load
   has filled it, or a load on another thread is filling it now. Bun
   fills the other slots, unless one of these holds:
   - one of them is bound to something else. The loader has then found
     a zlib in the addon's scope, also where no lookup finds one;
   - a word of data has an addend;
   - Bun cannot read a table, a symbol, a name or a slot;
   - dlsym finds one of the 13 names, in the global scope or in the
     addon's own tree;
   - a slot is not storable: it is outside the writable PT_LOAD ranges
     or inside PT_GNU_RELRO.
   In each of these cases Bun fills nothing. None of them is an error.
2. The import check runs as before. An import whose slot Bun fills
   counts as bound. With nothing to fill, an import of zlib is treated
   like every other import: a weak one is skipped, a strong one is asked
   about, and the first one that nothing defines refuses the addon by
   its name.
3. If the check has found nothing, Bun stores its functions in the
   slots.

So nothing is stored in an addon that is refused, and Bun never fills a
part of these imports. An addon keeps the zlib of its scope where a
bound slot or dlsym shows that zlib. An addon without a relocation that
names one of the 13 makes the same dlsym calls as before.

Two limits stay.

Bun reads only the object that has the initializer. A library that the
addon links and that imports zlib from the host is not filled: the
addon loads, and the library's first zlib call ends the process. The
import check has the same limit for every import of such a library.

No lookup searches the scope of another library that has loaded the
addon as its dependency. A zlib that is only there shows only in a
bound slot of one of the 13 names. If the addon's imports of the 13 are
all calls that the loader has not bound yet, Bun fills them. A zlib
function outside the 13 that the loader has bound there in dlopen(),
such as the address of deflateParams, then gets a stream of Bun's zlib.

The reader has one entry point for every target. musl and FreeBSD call
it with an empty table and get the import check alone: musl binds a
pending import again at each later dlopen(), which would undo a stored
slot, and nothing has run this on FreeBSD.

The test addon with the shape of uWebSockets.js has a second build that
deflates its response with the host's zlib.

Part of #9785
@robobun
robobun force-pushed the robobun/b72bafe4/node-register-entry branch from 1f6914b to 41b7658 Compare November 4, 2026 18:41
@robobun
robobun force-pushed the robobun/b72bafe4/addon-host-zlib branch from a8b74c2 to aae9f44 Compare November 4, 2026 18:41

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants