Skip to content

Commit a864eca

Browse files
fix(build): rebuild lsp_all.o when its included headers change
lsp_all.o is a unity object that #includes every lsp/*.c resolver; those include cbm.h, and CBMCall is copied BY VALUE across the lsp->pipeline boundary (cbm_calls_push). Its Make rule depended only on lsp_all.c, not on the headers it pulls in. So after CBMCall gained a field (is_method, DeusData#477) an incremental build kept a stale lsp_all.o with the old struct layout while the rest of the tree recompiled against the new one -- an ODR mismatch ASan flags as a stack-buffer-underflow in cbm_calls_push (the by-value copy under-reads the shorter stale struct). Clean builds (CI) always match, so it only bites incremental developer builds. Add an LSP_UNITY_DEPS prerequisite (lsp/*.c + lsp/*.h + lsp/generated/*.c + internal/cbm/*.h) to lsp_all.o and prod_lsp_all.o so the object rebuilds when any included header or unity source changes. Wildcard-based, so new LSP resolvers are covered automatically; explicit because this Makefile has no -MMD auto-deps. Verified: touching internal/cbm/cbm.h now rebuilds lsp_all.o (was stale before); clean build + full ASan suite green, rustlsp_dbg_macro_inner_call no longer aborts. Signed-off-by: Kris Kersey <kris@kerseyfabrications.com>
1 parent b075f05 commit a864eca

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

‎Makefile.cbm‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,18 @@ EXTRACTION_SRCS = \
135135
# LSP resolvers (compiled as one unit via lsp_all.c)
136136
LSP_SRCS = $(CBM_DIR)/lsp_all.c
137137

138+
# Header/source dependencies of the lsp_all unity object. lsp_all.c #includes
139+
# every lsp/*.c resolver, which in turn include cbm.h — and CBMCall is copied
140+
# BY VALUE across the lsp -> pipeline boundary (cbm_calls_push). This object is
141+
# compiled standalone and linked in, NOT recompiled with the rest on every link,
142+
# so it must list the headers/sources it pulls in. Without this, a changed struct
143+
# layout (e.g. a new CBMCall field) leaves a stale lsp_all.o with the old layout —
144+
# an ODR mismatch that under-reads the by-value struct copy. Explicit because this
145+
# Makefile does not use compiler auto-dependency (-MMD) generation.
146+
LSP_UNITY_DEPS = $(CBM_DIR)/lsp_all.c \
147+
$(wildcard $(CBM_DIR)/lsp/*.c $(CBM_DIR)/lsp/*.h \
148+
$(CBM_DIR)/lsp/generated/*.c $(CBM_DIR)/*.h)
149+
138150
# Tree-sitter runtime
139151
TS_RUNTIME_SRC = $(CBM_DIR)/ts_runtime.c
140152

@@ -434,7 +446,7 @@ $(BUILD_DIR)/%.o: $(CBM_DIR)/%.c | $(BUILD_DIR)
434446
$(BUILD_DIR)/ts_runtime.o: $(CBM_DIR)/ts_runtime.c | $(BUILD_DIR)
435447
$(CC) $(GRAMMAR_CFLAGS_TEST) -c -o $@ $<
436448

437-
$(BUILD_DIR)/lsp_all.o: $(CBM_DIR)/lsp_all.c | $(BUILD_DIR)
449+
$(BUILD_DIR)/lsp_all.o: $(LSP_UNITY_DEPS) | $(BUILD_DIR)
438450
$(CC) $(GRAMMAR_CFLAGS_TEST) $(SANITIZE) -c -o $@ $<
439451

440452
$(BUILD_DIR)/preprocessor.o: $(CBM_DIR)/preprocessor.cpp | $(BUILD_DIR)
@@ -524,7 +536,7 @@ $(BUILD_DIR)/prod_%.o: $(CBM_DIR)/%.c | $(BUILD_DIR)
524536
$(BUILD_DIR)/prod_ts_runtime.o: $(CBM_DIR)/ts_runtime.c | $(BUILD_DIR)
525537
$(CC) $(GRAMMAR_CFLAGS) -c -o $@ $<
526538

527-
$(BUILD_DIR)/prod_lsp_all.o: $(CBM_DIR)/lsp_all.c | $(BUILD_DIR)
539+
$(BUILD_DIR)/prod_lsp_all.o: $(LSP_UNITY_DEPS) | $(BUILD_DIR)
528540
$(CC) $(GRAMMAR_CFLAGS) -c -o $@ $<
529541

530542
$(BUILD_DIR)/prod_preprocessor.o: $(CBM_DIR)/preprocessor.cpp | $(BUILD_DIR)

0 commit comments

Comments
 (0)