pytorch - 💡(How to fix) Fix libtorch_cpu.so BLAS symbols are interposable, causing crashes when another BLAS is present in the process [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
pytorch/pytorch#182263Fetched 2026-05-04 04:57:48
View on GitHub
Comments
0
Participants
1
Timeline
15
Reactions
0
Participants
Timeline (top)
labeled ×5mentioned ×5subscribed ×5

Root Cause

Applications in HPC/scientific computing frequently combine PyTorch with libraries like PETSc, Trilinos, etc. These libraries often bring their own BLAS (OpenBLAS, MKL, etc.). Because PyTorch exports BLAS symbols with default visibility and uses PLT-based calls, it cannot reliably control which BLAS implementation is used.

Fix Action

Fix / Workaround

This leads to incorrect dispatch into an incompatible BLAS implementation and causes segmentation faults.

Current workaround

CPU: Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Address sizes: 39 bits physical, 48 bits virtual Byte Order: Little Endian CPU(s): 20 On-line CPU(s) list: 0-19 Vendor ID: GenuineIntel Model name: 12th Gen Intel(R) Core(TM) i7-12700H CPU family: 6 Model: 154 Thread(s) per core: 2 Core(s) per socket: 14 Socket(s): 1 Stepping: 3 CPU(s) scaling MHz: 15% CPU max MHz: 4700.0000 CPU min MHz: 400.0000 BogoMIPS: 5376.00 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt clwb intel_pt sha_ni xsaveopt xsavec xgetbv1 xsaves split_lock_detect user_shstk avx_vnni dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp hwp_pkg_req hfi vnmi umip pku ospke waitpkg gfni vaes vpclmulqdq rdpid movdiri movdir64b fsrm md_clear serialize arch_lbr ibt flush_l1d arch_capabilities ibpb_exit_to_user Virtualization: VT-x L1d cache: 544 KiB (14 instances) L1i cache: 704 KiB (14 instances) L2 cache: 11.5 MiB (8 instances) L3 cache: 24 MiB (1 instance) NUMA node(s): 1 NUMA node0 CPU(s): 0-19 Vulnerability Gather data sampling: Not affected Vulnerability Indirect target selection: Not affected Vulnerability Itlb multihit: Not affected Vulnerability L1tf: Not affected Vulnerability Mds: Not affected Vulnerability Meltdown: Not affected Vulnerability Mmio stale data: Not affected Vulnerability Reg file data sampling: Mitigation; Clear Register File Vulnerability Retbleed: Not affected Vulnerability Spec rstack overflow: Not affected Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization Vulnerability Spectre v2: Mitigation; Enhanced / Automatic IBRS; IBPB conditional; PBRSB-eIBRS SW sequence; BHI BHI_DIS_S Vulnerability Srbds: Not affected Vulnerability Tsa: Not affected Vulnerability Tsx async abort: Not affected Vulnerability Vmscape: Mitigation; IBPB before exit to userspace

Code Example

at::matmul(A, B);

---

cblas_dgemm_batch -> libopenblas.so.0
...
#0 0x0000000000000410 in ?? () 
#1 0x00007fffdd13b6cf in inner_small_matrix_thread () from /home/gary/projects/moose/petsc/arch-moose/lib/libopenblas.so.0 
#2 0x00007fffdd13b932 in dgemm_batch_thread () from /home/gary/projects/moose/petsc/arch-moose/lib/libopenblas.so.0 
#3 0x00007fffdd03cb87 in cblas_dgemm_batch () from /home/gary/projects/moose/petsc/arch-moose/lib/libopenblas.so.0 
#4 0x00007fffc680538a in at::native::mkl_gemm_batched(at::native::TransposeType, at::native::TransposeType, int, int, int, int, double, double const**, int, double const**, int, double, double**, int) () from /home/gary/micromamba/envs/neml2/lib/python3.11/site-packages/torch/lib/libtorch_cpu.so 
......

---

objdump -T libtorch_cpu.so | grep cblas_dgemm_batch

---

readelf -r libtorch_cpu.so | grep cblas_dgemm_batch

---

LD_PRELOAD=/path/to/libtorch_cpu.so

---

PyTorch version: 2.9.1+cu128
Is debug build: False
CUDA used to build PyTorch: 12.8
ROCM used to build PyTorch: N/A

OS: Ubuntu 24.04.4 LTS (x86_64)
GCC version: (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0
Clang version: 18.1.3 (1ubuntu1)
CMake version: version 4.1.2
Libc version: glibc-2.39

Python version: 3.11.13 | packaged by conda-forge | (main, Jun  4 2025, 14:48:23) [GCC 13.3.0] (64-bit runtime)
Python platform: Linux-6.8.0-110-generic-x86_64-with-glibc2.39
Is CUDA available: True
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: 
GPU models and configuration: GPU 0: NVIDIA GeForce RTX 3080 Ti Laptop GPU
Nvidia driver version: 580.126.09
cuDNN version: Could not collect
Is XPU available: False
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True
Caching allocator config: N/A

CPU:
Architecture:                            x86_64
CPU op-mode(s):                          32-bit, 64-bit
Address sizes:                           39 bits physical, 48 bits virtual
Byte Order:                              Little Endian
CPU(s):                                  20
On-line CPU(s) list:                     0-19
Vendor ID:                               GenuineIntel
Model name:                              12th Gen Intel(R) Core(TM) i7-12700H
CPU family:                              6
Model:                                   154
Thread(s) per core:                      2
Core(s) per socket:                      14
Socket(s):                               1
Stepping:                                3
CPU(s) scaling MHz:                      15%
CPU max MHz:                             4700.0000
CPU min MHz:                             400.0000
BogoMIPS:                                5376.00
Flags:                                   fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt clwb intel_pt sha_ni xsaveopt xsavec xgetbv1 xsaves split_lock_detect user_shstk avx_vnni dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp hwp_pkg_req hfi vnmi umip pku ospke waitpkg gfni vaes vpclmulqdq rdpid movdiri movdir64b fsrm md_clear serialize arch_lbr ibt flush_l1d arch_capabilities ibpb_exit_to_user
Virtualization:                          VT-x
L1d cache:                               544 KiB (14 instances)
L1i cache:                               704 KiB (14 instances)
L2 cache:                                11.5 MiB (8 instances)
L3 cache:                                24 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-19
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Mitigation; Clear Register File
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; Enhanced / Automatic IBRS; IBPB conditional; PBRSB-eIBRS SW sequence; BHI BHI_DIS_S
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Mitigation; IBPB before exit to userspace

Versions of relevant libraries:
[pip3] numpy==1.26.4
[pip3] nvidia-cublas-cu12==12.8.4.1
[pip3] nvidia-cuda-cupti-cu12==12.8.90
[pip3] nvidia-cuda-nvrtc-cu12==12.8.93
[pip3] nvidia-cuda-runtime-cu12==12.8.90
[pip3] nvidia-cudnn-cu12==9.10.2.21
[pip3] nvidia-cufft-cu12==11.3.3.83
[pip3] nvidia-curand-cu12==10.3.9.90
[pip3] nvidia-cusolver-cu12==11.7.3.90
[pip3] nvidia-cusparse-cu12==12.5.8.93
[pip3] nvidia-cusparselt-cu12==0.7.1
[pip3] nvidia-nccl-cu12==2.27.5
[pip3] nvidia-nvjitlink-cu12==12.8.93
[pip3] nvidia-nvtx-cu12==12.8.90
[pip3] torch==2.9.1
[pip3] triton==3.5.1
[conda] No relevant packages
RAW_BUFFERClick to expand / collapse

🐛 Describe the bug

When libtorch_cpu.so is used in an application that also links against another BLAS implementation (e.g., OpenBLAS via PETSc), PyTorch CPU matmul operations can crash due to symbol interposition of BLAS functions.

Specifically, libtorch_cpu.so defines symbols such as cblas_dgemm_batch, but calls to these symbols are made through a PLT (JUMP_SLOT), allowing them to be preempted at runtime by another BLAS library loaded earlier in the process.

This leads to incorrect dispatch into an incompatible BLAS implementation and causes segmentation faults.

Current behavior

In a mixed application (PyTorch + PETSc/OpenBLAS), calling:

at::matmul(A, B);

can result in a crash with a backtrace like:

cblas_dgemm_batch -> libopenblas.so.0
...
#0 0x0000000000000410 in ?? () 
#1 0x00007fffdd13b6cf in inner_small_matrix_thread () from /home/gary/projects/moose/petsc/arch-moose/lib/libopenblas.so.0 
#2 0x00007fffdd13b932 in dgemm_batch_thread () from /home/gary/projects/moose/petsc/arch-moose/lib/libopenblas.so.0 
#3 0x00007fffdd03cb87 in cblas_dgemm_batch () from /home/gary/projects/moose/petsc/arch-moose/lib/libopenblas.so.0 
#4 0x00007fffc680538a in at::native::mkl_gemm_batched(at::native::TransposeType, at::native::TransposeType, int, int, int, int, double, double const**, int, double const**, int, double, double**, int) () from /home/gary/micromamba/envs/neml2/lib/python3.11/site-packages/torch/lib/libtorch_cpu.so 
......

The crash occurs inside OpenBLAS, even though the call originated from PyTorch.

objdump -T libtorch_cpu.so | grep cblas_dgemm_batch

shows libtorch_cpu.so defines BLAS batch symbols.

readelf -r libtorch_cpu.so | grep cblas_dgemm_batch

shows R_X86_64_JUMP_SLOT ... cblas_dgemm_batch. This indicates the symbol is resolved dynamically at runtime and is interposable. If another blas is dynamically loaded earlier than torch, a segmentation with the above backtrace occurs.

Current workaround

Force libtorch_cpu.so to be loaded first using something like

LD_PRELOAD=/path/to/libtorch_cpu.so

or link it at the very front of the executable. This causes cblas_dgemm_batch to use the symbol embedded in libtorch_cpu.so and avoids the crash.

Potential fix

Applications in HPC/scientific computing frequently combine PyTorch with libraries like PETSc, Trilinos, etc. These libraries often bring their own BLAS (OpenBLAS, MKL, etc.). Because PyTorch exports BLAS symbols with default visibility and uses PLT-based calls, it cannot reliably control which BLAS implementation is used.

Below are some potential fixes suggested by AI:

  • Build libtorch_cpu.so with: -Bsymbolic or -Bsymbolic-functions or otherwise ensure internal calls bind locally
  • Do not export cblas_*, dgemm_*, etc. globally
  • Avoid PLT indirection for internal BLAS calls

I am unsure which one is easier to implement.

This issue is difficult to reproduce in isolation. However, if helpful, I can prepare a small repository for someone to try to reproduce.

Versions

PyTorch version: 2.9.1+cu128
Is debug build: False
CUDA used to build PyTorch: 12.8
ROCM used to build PyTorch: N/A

OS: Ubuntu 24.04.4 LTS (x86_64)
GCC version: (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0
Clang version: 18.1.3 (1ubuntu1)
CMake version: version 4.1.2
Libc version: glibc-2.39

Python version: 3.11.13 | packaged by conda-forge | (main, Jun  4 2025, 14:48:23) [GCC 13.3.0] (64-bit runtime)
Python platform: Linux-6.8.0-110-generic-x86_64-with-glibc2.39
Is CUDA available: True
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: 
GPU models and configuration: GPU 0: NVIDIA GeForce RTX 3080 Ti Laptop GPU
Nvidia driver version: 580.126.09
cuDNN version: Could not collect
Is XPU available: False
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True
Caching allocator config: N/A

CPU:
Architecture:                            x86_64
CPU op-mode(s):                          32-bit, 64-bit
Address sizes:                           39 bits physical, 48 bits virtual
Byte Order:                              Little Endian
CPU(s):                                  20
On-line CPU(s) list:                     0-19
Vendor ID:                               GenuineIntel
Model name:                              12th Gen Intel(R) Core(TM) i7-12700H
CPU family:                              6
Model:                                   154
Thread(s) per core:                      2
Core(s) per socket:                      14
Socket(s):                               1
Stepping:                                3
CPU(s) scaling MHz:                      15%
CPU max MHz:                             4700.0000
CPU min MHz:                             400.0000
BogoMIPS:                                5376.00
Flags:                                   fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt clwb intel_pt sha_ni xsaveopt xsavec xgetbv1 xsaves split_lock_detect user_shstk avx_vnni dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp hwp_pkg_req hfi vnmi umip pku ospke waitpkg gfni vaes vpclmulqdq rdpid movdiri movdir64b fsrm md_clear serialize arch_lbr ibt flush_l1d arch_capabilities ibpb_exit_to_user
Virtualization:                          VT-x
L1d cache:                               544 KiB (14 instances)
L1i cache:                               704 KiB (14 instances)
L2 cache:                                11.5 MiB (8 instances)
L3 cache:                                24 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-19
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Mitigation; Clear Register File
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; Enhanced / Automatic IBRS; IBPB conditional; PBRSB-eIBRS SW sequence; BHI BHI_DIS_S
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Mitigation; IBPB before exit to userspace

Versions of relevant libraries:
[pip3] numpy==1.26.4
[pip3] nvidia-cublas-cu12==12.8.4.1
[pip3] nvidia-cuda-cupti-cu12==12.8.90
[pip3] nvidia-cuda-nvrtc-cu12==12.8.93
[pip3] nvidia-cuda-runtime-cu12==12.8.90
[pip3] nvidia-cudnn-cu12==9.10.2.21
[pip3] nvidia-cufft-cu12==11.3.3.83
[pip3] nvidia-curand-cu12==10.3.9.90
[pip3] nvidia-cusolver-cu12==11.7.3.90
[pip3] nvidia-cusparse-cu12==12.5.8.93
[pip3] nvidia-cusparselt-cu12==0.7.1
[pip3] nvidia-nccl-cu12==2.27.5
[pip3] nvidia-nvjitlink-cu12==12.8.93
[pip3] nvidia-nvtx-cu12==12.8.90
[pip3] torch==2.9.1
[pip3] triton==3.5.1
[conda] No relevant packages

cc @seemethere @malfet @atalman @tinglvv @nWEIdia

extent analysis

TL;DR

The most likely fix is to rebuild libtorch_cpu.so with the -Bsymbolic or -Bsymbolic-functions flag to prevent symbol interposition of BLAS functions.

Guidance

  • Verify that the crash occurs due to symbol interposition by checking the backtrace and the output of objdump -T libtorch_cpu.so | grep cblas_dgemm_batch and readelf -r libtorch_cpu.so | grep cblas_dgemm_batch.
  • Consider rebuilding libtorch_cpu.so with the -Bsymbolic or -Bsymbolic-functions flag to bind internal calls locally and prevent symbol interposition.
  • As a temporary workaround, use LD_PRELOAD=/path/to/libtorch_cpu.so to force libtorch_cpu.so to be loaded first and avoid the crash.
  • Investigate alternative solutions, such as not exporting cblas_* symbols globally or avoiding PLT indirection for internal BLAS calls.

Example

No code snippet is provided as the issue is related to the build process and symbol interposition.

Notes

The issue is difficult to reproduce in isolation, and a small repository may be needed to test potential fixes. The provided information suggests that the crash is caused by symbol interposition, but further investigation may be required to confirm the root cause.

Recommendation

Apply the workaround using LD_PRELOAD=/path/to/libtorch_cpu.so until a permanent fix can be implemented, such as rebuilding libtorch_cpu.so with the -Bsymbolic or -Bsymbolic-functions flag.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

pytorch - 💡(How to fix) Fix libtorch_cpu.so BLAS symbols are interposable, causing crashes when another BLAS is present in the process [1 participants]