Fix macOS link: stub the CUDA Chase entry points for CPU-only builds

deep_repair.c references chase_cuda_available/_scan1 (weak), but no CPU-only stub defined them, so the macOS link failed with undefined _chase_cuda_available/_chase_cuda_scan1 (run 7, both arches) -- the merge kept the BCH stub but the Chase symbols had none. Add chase_cuda_stub.c (available = 0, scan1 = -2) and wire it into CUDA_STUB_OBJ on the nvcc-absent path, so every tool that links deep_repair.o resolves. Verified both paths on hot_house: full make test green with real CUDA objects, and a no-nvcc build links and repairs (9-bit corruption recovered at L1 via the CPU Chase).
This commit is contained in:
cnmcdee committed 2026-12-04 08:02:12 -05:00
1 parent c6e06a0d48
commit 88d1e3b183
2 files changed
+76 -16

No files matched your search

+24 -16
View File
@@ -13,13 +13,15 @@ PREFIX = /usr/local
# chase_cuda.o -- CUDA Chase-1 scan for deep repair (t=8 only);
# linked into lzply and lzply_deep_repair, with a
# CPU fallback via weak references.
# Without nvcc, bch_cuda_stub.o is linked instead, so the CUDA entry
# points always resolve -- see the stub comment below. The stub is
# required on macOS: ld64 does not resolve __attribute__((weak))
# declarations to NULL the way GNU ld does, so a CPU-only build
# failed at link time with undefined _bch_cuda_available/_encode/
# _decode symbols. The stub is never built alongside bch_cuda.o, so
# the symbols are defined exactly once.
# Without nvcc, the *_cuda_stub.o objects are linked instead, so
# the CUDA entry points always resolve -- see the stub comment
# below. The stubs are required on macOS: ld64 does not resolve
# __attribute__((weak)) declarations to NULL the way GNU ld does,
# so a CPU-only build failed at link time with undefined
# _bch_cuda_available/_encode/_decode symbols (and, after the
# chase-wired merge, _chase_cuda_available/_scan1). A stub is
# never built alongside its CUDA object, so the symbols are
# defined exactly once.
# These definitions MUST stay above every rule that references
# $(CUDA_OBJ): make expands prerequisites when the rule is read, so
# a definition below the liblzply.a rule would silently leave
@@ -44,17 +46,20 @@ ifneq ($(wildcard $(NVCC)),)
CHASE_CUDA_OBJ = chase_cuda.o
endif
# CPU-only stub: when nvcc is absent, bch_cuda_stub.o defines the
# three CUDA entry points (available() = 0, encode = 0, decode = -2),
# so bch.c's references always resolve. This is required on macOS:
# ld64 does not resolve __attribute__((weak)) declarations to NULL
# the way GNU ld does, so a CPU-only build failed at link time with
# undefined _bch_cuda_available/_encode/_decode symbols. The stub
# is never built alongside bch_cuda.o, so the symbols are defined
# exactly once.
# CPU-only stubs: when nvcc is absent, bch_cuda_stub.o defines the
# three BCH CUDA entry points (available() = 0, encode = 0,
# decode = -2) and chase_cuda_stub.o defines the two Chase CUDA
# entry points (available() = 0, scan1 = -2), so bch.c's and
# deep_repair.c's references always resolve. This is required on
# macOS: ld64 does not resolve __attribute__((weak)) declarations
# to NULL the way GNU ld does, so a CPU-only build failed at link
# time with undefined _bch_cuda_available/_encode/_decode symbols
# (and, after the chase-wired merge, _chase_cuda_available/_scan1).
# A stub is never built alongside its CUDA object, so the symbols
# are defined exactly once.
CUDA_STUB_OBJ =
ifeq ($(NVCC),)
CUDA_STUB_OBJ = bch_cuda_stub.o
CUDA_STUB_OBJ = bch_cuda_stub.o chase_cuda_stub.o
endif
all: lzply lzply_mount lzply_stat lzply_heal lzply_check lzply_refresh lzply_hyper lz_rs lzply_deep_repair
@@ -79,6 +84,9 @@ bch.o: bch.c bch.h bch_polys.h
bch_cuda_stub.o: bch_cuda_stub.c bch_cuda.h bch.h
$(CC) $(CFLAGS) -c -o $@ bch_cuda_stub.c
chase_cuda_stub.o: chase_cuda_stub.c chase_cuda.h bch.h
$(CC) $(CFLAGS) -c -o $@ chase_cuda_stub.c
# CUDA BCH remainder rules (variables are defined at the top).
ifneq ($(NVCC),)
bch_cuda.o: bch_cuda.cu bch_cuda.h bch.h bch_polys.h
+52
View File
@@ -0,0 +1,52 @@
/* chase_cuda_stub.c - CPU-only fallback for the CUDA Chase-1 entry points.
*
* Defines the two symbols deep_repair.c references (chase_cuda_available,
* chase_cuda_scan1) for builds without nvcc, so a CPU-only link always
* resolves. The stub reports "no GPU": the caller in deep_repair.c then
* takes the CPU Chase-1 path, exactly as it does when a CUDA build is
* present but no device is found.
*
* This exists for the same reason as bch_cuda_stub.c: the weak-symbol
* fallback it replaces does not work on macOS. deep_repair.c declares
* these functions __attribute__((weak)), expecting them to resolve to
* NULL when no CUDA object is linked. GNU ld does that; macOS ld64
* does not -- a weak declaration is a weak definition, not a weak
* import, so the link fails with undefined _chase_cuda_available /
* _chase_cuda_scan1 symbols (run 7 on main, both arm64 and x86_64).
* Defining the symbols outright removes all reliance on
* linker-specific weak-symbol behaviour, on every platform.
*
* The stub is built only when nvcc is absent (see the Makefile:
* CUDA_STUB_OBJ is empty whenever CHASE_CUDA_OBJ is set), so the
* symbols are defined exactly once in every build.
*/
#include <stddef.h>
#include <stdint.h>
#include "bch.h"
#include "chase_cuda.h"
int chase_cuda_available(void)
{
return 0;
}
int chase_cuda_scan1(const uint8_t *in, size_t in_len, size_t data_len,
const bch_poly_t *p, uint8_t *cands, int max_cands,
const size_t *suspects, int nsuspects,
long *trials_out, long *split_pass_out,
long *codewords_out)
{
(void)in;
(void)in_len;
(void)data_len;
(void)p;
(void)cands;
(void)max_cands;
(void)suspects;
(void)nsuspects;
(void)trials_out;
(void)split_pass_out;
(void)codewords_out;
return -2;
}