build(zig): keep all symbols for native Lua modules #41361

Native Lua modules loaded with `require` or `package.loadlib` resolve Lua
C API symbols from the nvim executable itself. Those symbols must stay in
the binary even when nothing inside nvim references them.

`rdynamic` is enough on Linux. On macOS the linker dead-strips
unreferenced symbols before rdynamic exports them, so `_lua_tothread` is
missing from the executable and loading such a module fails with:

    symbol not found in flat namespace '_lua_tothread'

Disable section garbage collection so all non-static symbols are kept.
This commit is contained in:
Max Coplan
2026-08-18 01:16:35 -07:00
committed by GitHub
parent 4a77d1e1db
commit 750c665ab3

View File

@@ -498,6 +498,7 @@ pub fn build(b: *std.Build) !void {
.root_module = nvim_mod,
}) else b.addExecutable(.{ .name = "nvim", .root_module = nvim_mod });
nvim_exe.rdynamic = true; // -E
nvim_exe.link_gc_sections = false; // prevent linker from gc:ing exported symbols #40622
if (emscripten_libc_path) |lp| nvim_exe.setLibCFile(lp);
if (is_wasm) nvim_exe.entry = .disabled;
if (is_wasm) nvim_exe.linker_allow_shlib_undefined = true;