diff --git a/crates/solidcore-ffi/src/units/surface_offset_surface.rs b/crates/solidcore-ffi/src/units/surface_offset_surface.rs index eccd5daf42..e2690834cc 100644 --- a/crates/solidcore-ffi/src/units/surface_offset_surface.rs +++ b/crates/solidcore-ffi/src/units/surface_offset_surface.rs @@ -1063,8 +1063,14 @@ mod tests { assert!(refused(&script(&off, &[Step::Extend { dist, cont }])), "{dist:e}"); assert!(t.elapsed() < crate::offset_reference::DEADLINE); } - // a normal extension of the same surface is compared - assert!(script(&off, &[Step::Extend { dist: 0.1, cont: 5 }]).is_ok()); + // a normal extension of the same surface is compared where the worker has its + // NLib link wrappers (GNU ld --wrap, Linux); elsewhere every extension is refused + let normal = script(&off, &[Step::Extend { dist: 0.1, cont: 5 }]); + if cfg!(target_os = "linux") { + assert!(normal.is_ok()); + } else { + assert!(refused(&normal)); + } } #[test] diff --git a/harness/cpp/offset_worker.cpp b/harness/cpp/offset_worker.cpp index ceb0742053..ef6d3d0226 100644 --- a/harness/cpp/offset_worker.cpp +++ b/harness/cpp/offset_worker.cpp @@ -115,7 +115,6 @@ extern "C" NL_FLAG __wrap_N_SrfCopy(NL_SURFACE* source, NL_SURFACE* target, return __real_N_SrfCopy(source, target, stack); } -extern "C" int sc_offset_extension_guards() { return 1; } #endif // SC_OFFSET_NO_LINK_WRAP template bool read(T& value) @@ -129,6 +128,9 @@ template void write(const T& value) int main() { +#ifndef SC_OFFSET_NO_LINK_WRAP + sc_offset_extension_guards_enabled = 1; +#endif int32_t op; uint64_t count; if (!read(op) || !read(count) || count == 0 || count > 1048576) return 2; diff --git a/harness/cpp/shim/sc_offset_guard.h b/harness/cpp/shim/sc_offset_guard.h index 48028e94aa..4f0720c0a0 100644 --- a/harness/cpp/shim/sc_offset_guard.h +++ b/harness/cpp/shim/sc_offset_guard.h @@ -5,9 +5,9 @@ // offset shim and its worker-only link wrappers; unwinds into the shim boundary. struct ScOffsetUnsafeInput {}; -// Nonzero when the offset worker is linked with its NLib wrappers (GNU ld --wrap): the -// guards for UB-107 and the HANG-6/HANG-15 extension searches. The shim's weak default -// returns 0; the worker's strong definition overrides it where the wrappers exist. -extern "C" int sc_offset_extension_guards(); -inline bool sc_offset_extensions_guarded() { return sc_offset_extension_guards() != 0; } +// Set to 1 by the offset worker's main() when it is linked with its NLib wrappers (GNU +// ld --wrap): the guards for UB-107 and the HANG-6/HANG-15 extension searches. Defined +// as 0 in the shim (a plain variable, no weak symbols: the shim builds everywhere). +extern "C" int sc_offset_extension_guards_enabled; +inline bool sc_offset_extensions_guarded() { return sc_offset_extension_guards_enabled != 0; } #endif diff --git a/harness/cpp/shim/surface_offset_surface.cpp b/harness/cpp/shim/surface_offset_surface.cpp index 9247ac8771..7c28270109 100644 --- a/harness/cpp/shim/surface_offset_surface.cpp +++ b/harness/cpp/shim/surface_offset_surface.cpp @@ -48,6 +48,9 @@ #include #include +// (see sc_offset_guard.h; set by the offset worker) +extern "C" int sc_offset_extension_guards_enabled = 0; + namespace { // Entry ops (keep in sync with crates/solidcore-ffi/src/units/surface_offset_surface.rs). @@ -199,8 +202,6 @@ bool delegates_to_plane(SmOffsetSurface* s, const SmPoint2d& uv, ULONG hu, ULONG return SM_CAST_PTR(SmPlane, base) != NULL; } -extern "C" __attribute__((weak)) int sc_offset_extension_guards() { return 0; } - // UB-116: with bOnlyUpperHalf, EvaluatePlainOrSimple's non-zero path writes the mixed // derivatives at their full-layout indices, past a caller array sized (hu+1)(hv+1). // Mirror its checks in order: offset order above 3 and an offset nested twice fail