Skip to content

Commit 175f62a

Browse files
authored
ffi: cfg-gate local tcc_delete extern to match bun_tcc_sys (#30743)
`src/runtime/ffi/mod.rs` declares its own unconditional `extern "C" { fn tcc_delete }`, separate from `bun_tcc_sys::tcc_externs!` which correctly cfg-gates the libtcc externs on `cfg.tinycc` (= NOT android / freebsd / windows-aarch64, where `libtcc.a` isn't built). `Function::drop` calls it inside `if let Some(state)` — `state` is never `Some` on those targets so the call is dead at runtime, but with cargo LTO overridden off (asan / linker-plugin-lto path in `rust.ts`) the symbol reference survives into the staticlib and link fails: ``` lld-link: error: undefined symbol: tcc_delete ``` Gate the local extern on the same predicate as `tcc_externs!` and provide an `unreachable!()` stub on the disabled targets, mirroring what `src/tcc_sys/tcc.rs` already does.
1 parent 952d337 commit 175f62a

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

src/runtime/ffi/mod.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,25 @@ mod TCC {
118118
pub struct State;
119119
}
120120
// Raw extern so the handle can be freed even while the method-ful
121-
// `bun_tcc_sys::State` API stays gated.
121+
// `bun_tcc_sys::State` API stays gated. Keep this predicate in sync with
122+
// `bun_tcc_sys::tcc_externs!` / `cfg.tinycc` in `scripts/build/config.ts`.
122123
// TODO(port): move to <area>_sys
124+
#[cfg(not(any(
125+
target_os = "android",
126+
target_os = "freebsd",
127+
all(windows, target_arch = "aarch64")
128+
)))]
123129
unsafe extern "C" {
124130
pub fn tcc_delete(s: *mut State);
125131
}
132+
#[cfg(any(
133+
target_os = "android",
134+
target_os = "freebsd",
135+
all(windows, target_arch = "aarch64")
136+
))]
137+
pub unsafe fn tcc_delete(_s: *mut State) {
138+
unreachable!("tcc_delete: TinyCC not built on this target (cfg.tinycc = false)");
139+
}
126140
}
127141

128142
// ─── JIT write-protect helper ────────────────────────────────────────────────

0 commit comments

Comments
 (0)