From e0f2e295091dc293561a15d302d22bf96d810018 Mon Sep 17 00:00:00 2001 From: Elliot Saba Date: Mon, 29 Jul 2024 22:10:30 -0700 Subject: [PATCH] Add `lbt_forwarded_funcs()` to debug LBT forwarding issues (#55302) It can be very helpful, when struggling with LBT forwarding, to see what functions were actually forwarded to a new library. This utility function makes it easy to query which functions are forwarded to that library. --- stdlib/LinearAlgebra/src/lbt.jl | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/stdlib/LinearAlgebra/src/lbt.jl b/stdlib/LinearAlgebra/src/lbt.jl index 02b4411566290..606ddedbe1343 100644 --- a/stdlib/LinearAlgebra/src/lbt.jl +++ b/stdlib/LinearAlgebra/src/lbt.jl @@ -284,6 +284,25 @@ function lbt_find_backing_library(symbol_name, interface::Symbol; end +""" + lbt_forwarded_funcs(config::LBTConfig, lib::LBTLibraryInfo) + +Given a backing library `lib`, return the list of all functions that are +forwarded to that library, as a vector of `String`s. +""" +function lbt_forwarded_funcs(config::LBTConfig, lib::LBTLibraryInfo) + forwarded_funcs = String[] + for (symbol_idx, symbol) in enumerate(config.exported_symbols) + forward_byte_offset = div(symbol_idx - 1, 8) + forward_byte_mask = 1 << mod(symbol_idx - 1, 8) + if lib.active_forwards[forward_byte_offset+1] & forward_byte_mask != 0x00 + push!(forwarded_funcs, symbol) + end + end + return forwarded_funcs +end + + ## NOTE: Manually setting forwards is referred to as the 'footgun API'. It allows truly ## bizarre and complex setups to be created. If you run into strange errors while using ## it, the first thing you should ask yourself is whether you've set things up properly.