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.
This commit is contained in:
Chris Tate
2026-10-27 02:49:05 -05:00
parent 60d5dc8ab1
commit 429aa8273d
+6 -3
View File
@@ -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);