Skip to content

Conversation

@imciner2
Copy link
Contributor

@imciner2 imciner2 commented Oct 15, 2025

On Linux, dlsym() will search the entire dependency tree of the library we load, so if we are trying to load a library that is linked against LBT, then dlsym() could give us back the symbol in LBT instead of the one actually in the target library.

To prevent this, we need to check to see if the returned symbol is ours, and ignore it if it is ours.

For example, I saw this causing problems when trying to load LAPACK_jll, which is linked against LBT, because LBT was thinking that it had no suffix because it found the LBT symbol for isamax_.

julia> using LAPACK_jll, LinearAlgebra

julia> BLAS.lbt_forward(LAPACK_jll.liblapack, verbose=true, clear=true)
Generating forwards to /home/imcinerney/.julia/artifacts/8a7dc669fd077b3ecbe70b2a4fdb7db0a94a16f1/lib/liblapack.so (clear: 1, verbose: 1, suffix_hint: '(null)')
Symbol suffix search
Symbol name: isamax_
Symbol addr: 0x7f52ac4282ca
LBT symbol addr: 0x7f52ac4282ca
 -> Autodetected symbol suffix ""
Error: no BLAS/LAPACK library loaded for isamax_()
Unable to autodetect interface type of "/home/imcinerney/.julia/artifacts/8a7dc669fd077b3ecbe70b2a4fdb7db0a94a16f1/lib/liblapack.so"
0

After this change, I can load LAPACK_jll:

julia> using LAPACK_jll, LinearAlgebra

julia> BLAS.lbt_forward(LAPACK_jll.liblapack, verbose=true, clear=true)
Generating forwards to /home/imcinerney/.julia/artifacts/8a7dc669fd077b3ecbe70b2a4fdb7db0a94a16f1/lib/liblapack.so (clear: 1, verbose: 1, suffix_hint: '(null)')
Symbol suffix search
Symbol name: isamax_
New       symbol addr: 0x7f741e02832a
LBT LP64  symbol addr: 0x7f741e02832a
LBT ILP64 symbol addr: 0x7f741e040118
Symbol name: isamax__
New       symbol addr: (nil)
LBT LP64  symbol addr: 0x7f741e02832a
LBT ILP64 symbol addr: 0x7f741e040118
Symbol name: isamax___
New       symbol addr: (nil)
LBT LP64  symbol addr: 0x7f741e02832a
LBT ILP64 symbol addr: 0x7f741e040118
Symbol name: isamax_64
New       symbol addr: (nil)
LBT LP64  symbol addr: 0x7f741e02832a
LBT ILP64 symbol addr: 0x7f741e040118
Symbol name: isamax__64
New       symbol addr: (nil)
LBT LP64  symbol addr: 0x7f741e02832a
LBT ILP64 symbol addr: 0x7f741e040118
Symbol name: isamax_64_
New       symbol addr: 0x7f741e040118
LBT LP64  symbol addr: 0x7f741e02832a
LBT ILP64 symbol addr: 0x7f741e040118
Symbol name: isamax__64_
New       symbol addr: (nil)
LBT LP64  symbol addr: 0x7f741e02832a
LBT ILP64 symbol addr: 0x7f741e040118
Symbol name: isamax__64__
New       symbol addr: (nil)
LBT LP64  symbol addr: 0x7f741e02832a
LBT ILP64 symbol addr: 0x7f741e040118
Symbol name: isamax___64___
New       symbol addr: (nil)
LBT LP64  symbol addr: 0x7f741e02832a
LBT ILP64 symbol addr: 0x7f741e040118
Symbol name: dpotrf_
New       symbol addr: 0x7f741e0272e9
LBT LP64  symbol addr: 0x7f741e0272e9
LBT ILP64 symbol addr: 0x7f741e03f0d7
Symbol name: dpotrf__
New       symbol addr: (nil)
LBT LP64  symbol addr: 0x7f741e0272e9
LBT ILP64 symbol addr: 0x7f741e03f0d7
Symbol name: dpotrf___
New       symbol addr: (nil)
LBT LP64  symbol addr: 0x7f741e0272e9
LBT ILP64 symbol addr: 0x7f741e03f0d7
Symbol name: dpotrf_64
New       symbol addr: (nil)
LBT LP64  symbol addr: 0x7f741e0272e9
LBT ILP64 symbol addr: 0x7f741e03f0d7
Symbol name: dpotrf__64
New       symbol addr: (nil)
LBT LP64  symbol addr: 0x7f741e0272e9
LBT ILP64 symbol addr: 0x7f741e03f0d7
Symbol name: dpotrf_64_
New       symbol addr: 0x7f73fb839f30
LBT LP64  symbol addr: 0x7f741e0272e9
LBT ILP64 symbol addr: 0x7f741e03f0d7
 -> Autodetected symbol suffix "64_"
 -> Autodetected interface ILP64 (64-bit)
 -> Autodetected normal complex return style
 -> Autodetected gfortran calling convention
 -> CBLAS detected
Processed 5146 symbols; forwarded 1923 symbols with 64-bit interface and mangling to a suffix of "64_"
1923

julia> 

On Linux, dlsym() will search the entire dependency tree of the library
we load, so if we are trying to load a library that is linked against
LBT, then dlsym() could give us back the symbol in LBT instead of the
one actually in the target library.

To prevent this, we need to check to see if the returned symbol is ours,
and ignore it if it is ours.
@imciner2 imciner2 marked this pull request as draft October 16, 2025 01:00
@imciner2
Copy link
Contributor Author

Putting this to a draft because I am working on a test for loading LAPACK_jll to catch this, and also I think I need to update the other lookup_symbol calls in the autodetection logic to ignore the LBT symbols. Because I think we might be actually testing the interface type using the LBT isamax_64_ function instead of the LAPACK dpotrf_64_ function when loading LAPACK_jll. (I think that is safe for LAPACK_jll because it has the suffix for ILP64, but if it was an ILP64 LAPACK that didn't have the suffix there would be a problem).

@imciner2 imciner2 added the bug Something isn't working label Oct 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants