Skip to content

Commit d5543a9

Browse files
committed
Improve error messages by including symbol index in trampolines
We smuggle symbol indices in a scratch register through our trampolines, allowing our default error printing function to rescue out the appropriate symbol index, and turn that into a symbol name. While this is fancy, reduces code size, and makes me feel clever, it's also not very reproducible for other projects that wish to replicate this technique without requiring that the scratch register be preserved long enough for their handling code to get at it. In such a case, the fallback implementation would be to generate function stubs for every symbol individually. A Julia implementation of this follows: First, a module is defined with error stubs for every symbol: ```julia module LBTDebuggingFuncs import LinearAlgebra.BLAS: lbt_get_config for func_name in lbt_get_config().exported_symbols @eval $(Symbol(func_name))() = println("Error: no BLAS/LAPACK library loaded for ", $(func_name), "()!") end end # module LBTDebuggingFuncs ``` Next, these functions are inserted as the base layer of forwards for LBT: ```julia symbol_list = lbt_get_config().exported_symbols for (symbol_idx, symbol) in enumerate(symbol_list) func = getproperty(LBTDebuggingFuncs, Symbol(symbol)) debug_fptr = @cfunction($func, Cvoid, ()) lbt_set_forward_by_index(symbol_idx-1, debug_fptr, :ilp64) lbt_set_forward_by_index(symbol_idx-1, debug_fptr, :lp64) end ``` After that, subsequent `lbt_forward()` calls (without `clear` set, of course) will fill in forwards to the actual backing BLAS calls, but those left behind will have customized error messages, denoting which BLAS call was unsupported.
1 parent ff05ebb commit d5543a9

15 files changed

+5206
-5143
lines changed

ext/gensymbol/generate_func_list.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ echo "#ifndef EXPORTED_FUNCS" >> "${OUTPUT_FILE}"
3737
echo "#define EXPORTED_FUNCS(XX) \\" >> "${OUTPUT_FILE}"
3838
NUM_EXPORTED=0
3939
for s in ${EXPORTED_FUNCS}; do
40-
echo " XX(${s}) \\" >> "${OUTPUT_FILE}"
40+
echo " XX(${s}, ${NUM_EXPORTED}) \\" >> "${OUTPUT_FILE}"
4141
NUM_EXPORTED=$((${NUM_EXPORTED} + 1))
4242
[ $((${NUM_EXPORTED} % 100)) == 0 ] && echo -n "."
4343
done

src/Make.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ else
5353
SONAME_FLAG := -Wl,-soname=$(LIB_MAJOR_VERSION)
5454
endif
5555

56-
LBT_CFLAGS := -g -O2 -std=c99 $(FPIC) -DLIBRARY_EXPORTS -D_GNU_SOURCE $(CFLAGS)
56+
LBT_CFLAGS := -g -O2 -std=gnu99 $(FPIC) -DLIBRARY_EXPORTS -D_GNU_SOURCE -DARCH_$(ARCH) $(CFLAGS)
5757
LBT_LDFLAGS := $(LDFLAGS)
5858

5959
ifeq ($(OS),Linux)

0 commit comments

Comments
 (0)