From 429aa8273de6d2f0bee0d3a9c4c3c214b60397d3 Mon Sep 17 00:00:00 2001 From: Chris Tate Date: Tue, 27 Oct 2026 02:49:05 -0500 Subject: [PATCH] Keep the heap census hook out of library archives Libraries never build the census (heapCensusOf), but the runtime's weak scr_census_write reference made library archives list an external symbol outside their declared set. Declare and call it only in programs. --- packages/runtime/src/scr_lib.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/runtime/src/scr_lib.c b/packages/runtime/src/scr_lib.c index df36f063e2..ad42a5824c 100644 --- a/packages/runtime/src/scr_lib.c +++ b/packages/runtime/src/scr_lib.c @@ -225,15 +225,16 @@ static void scr_module_registry_cleanup(void) { * own cleanup only when the value is first materialized. That is equivalent * at process exit and retains the RC-audit cleanup guarantee for the values a * program actually observes. */ -#if defined(__linux__) +#if defined(__linux__) && !defined(SCR_LIB) /* The heap census of a program built with SCRIPTC_HEAP_CENSUS * (heap-census.ts) writes its counters at exit, from here and from - * scr_process_exit; every other build leaves the weak reference null. */ + * scr_process_exit; every other program leaves the weak reference null. + * Libraries have no census, and their archives declare no such symbol. */ extern void scr_census_write(void) __attribute__((weak)); #endif static void scr_lib_cleanup(void) { -#if defined(__linux__) +#if defined(__linux__) && !defined(SCR_LIB) if (scr_census_write != NULL) scr_census_write(); #endif scr_module_registry_cleanup(); @@ -2147,7 +2148,9 @@ void scr_process_exit(double code) { fflush(stdout); #if defined(__linux__) if (__llvm_profile_write_file != NULL) (void)__llvm_profile_write_file(); +#ifndef SCR_LIB if (scr_census_write != NULL) scr_census_write(); +#endif scr_detach_teardown(); #endif _Exit((int)code);