Files
hakmem/core/link_stubs.c
Moe Charm (CI) 12c36afe46 Fix TSan build: Add weak stubs for sanitizer compatibility
Added weak stubs to core/link_stubs.c for symbols that are not needed
in HAKMEM_FORCE_LIBC_ALLOC_BUILD=1 (TSan/ASan) builds:

Stubs added:
- g_bump_chunk (int)
- g_tls_bcur, g_tls_bend (__thread uint8_t*[8])
- smallmid_backend_free()
- expand_superslab_head()

Also added: #include <stdint.h> for uint8_t

Impact:
- TSan build: PASS (larson_hakmem_tsan successfully built)
- Phase 2 ready: Can now use TSan to debug Larson crashes

Next: Use TSan to investigate Larson 47% crash rate

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-27 05:19:56 +09:00

53 lines
2.1 KiB
C

#include <stddef.h>
#include <stdlib.h>
#include <stdint.h>
#include <sys/types.h>
// Weak, no-op stubs to satisfy link in configurations where
// optional components are compiled out or gated by flags.
// Real implementations (when present) will override these.
__attribute__((weak)) void hak_tiny_prewarm_tls_cache(void) {}
// Weak stubs for remote tracking (avoid LTO link errors when tiny_remote.c is GC'ed)
struct SuperSlab; // forward decl to avoid heavy includes
__attribute__((weak)) void tiny_remote_track_on_local_free(struct SuperSlab* ss, int slab_idx, void* node, const char* stage, unsigned int tid) {
(void)ss; (void)slab_idx; (void)node; (void)stage; (void)tid;
}
__attribute__((weak)) void tiny_remote_track_expect_alloc(struct SuperSlab* ss, int slab_idx, void* node, const char* stage, unsigned int tid) {
(void)ss; (void)slab_idx; (void)node; (void)stage; (void)tid;
}
__attribute__((weak)) void* pool_alloc(size_t size) {
// Fallback to malloc if Pool TLS not linked
return malloc(size);
}
__attribute__((weak)) void pool_free(void* ptr) {
// Fallback to free if Pool TLS not linked
free(ptr);
}
// Pool TLS registry lookup stub (used by Front Gate classifier when POOL_TLS is enabled)
__attribute__((weak)) int pool_reg_lookup(void* ptr, pid_t* tid_out, int* class_idx_out) {
(void)ptr; if (tid_out) *tid_out = 0; if (class_idx_out) *class_idx_out = -1; return 0; // not found
}
// Memory profile print stub (bench_comprehensive references this symbol)
__attribute__((weak)) void hak_tiny_print_memory_profile(void) {}
// TSan/ASan build stubs (avoid link errors when HAKMEM_FORCE_LIBC_ALLOC_BUILD=1)
// These symbols are referenced in refill/bump allocation paths but not needed for sanitizer builds
__attribute__((weak)) int g_bump_chunk = 1;
__attribute__((weak)) __thread uint8_t* g_tls_bcur[8] = {0};
__attribute__((weak)) __thread uint8_t* g_tls_bend[8] = {0};
__attribute__((weak)) void smallmid_backend_free(void* ptr, int unused) {
(void)ptr; (void)unused;
}
__attribute__((weak)) int expand_superslab_head(void* head) {
(void)head;
return -1; // Failure (not needed in sanitizer build)
}