Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix _xerbla_ linking on older Mac versions #4353

Conversation

erikbs
Copy link
Contributor

@erikbs erikbs commented Dec 3, 2023

See issue #4347 for problem description. The symbol _xerbla_ was missing from the libopenblas.a archive file, so weak linking was introduced for Darwin < 20 in PR #4348. This allowed OpenBLAS to compile on older Mac versions, but it did not actually fix the problem. The error would instead show up when trying to load the library, for example through NumPy:

>>> import numpy
Traceback (most recent call last):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/numpy/core/__init__.py", line 24, in <module>
    from . import multiarray
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/numpy/core/multiarray.py", line 10, in <module>
    from . import overrides
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/numpy/core/overrides.py", line 8, in <module>
    from numpy.core._multiarray_umath import (
ImportError: dlopen(/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/numpy/core/_multiarray_umath.cpython-311-darwin.so, 2): Symbol not found: _xerbla_
  Referenced from: /opt/local/lib/libopenblas.0.dylib
  Expected in: flat namespace
 in /opt/local/lib/libopenblas.0.dylib

I found out that OpenBLAS builds two xerbla.c.o files, only one of which contains symbols, and links in the one with symbols explicitly on Darwin < 20. However, its timestamp is older than the object file without symbols, so ar -ru does nothing. Thus, the _xerbla_ symbol will never be present in the final library.

My proposal is to write xerbla.c.o into the archive using ar -rs instead of allowing weak linking. With that option, the xerbla.c.o with symbols is written into the archive regardless of compilation order.

(Link to my bug report to MacPorts: https://trac.macports.org/ticket/68810)

Write xerbla.c.o into archive regardless of timestamp by using ar -rs
instead of ar -ru.
@erikbs
Copy link
Contributor Author

erikbs commented Dec 9, 2023

Info: patch accepted into MacPorts

@martin-frbg
Copy link
Collaborator

I need to trawl through reference-lapack tickets but ISTR they solved it by enforcing flat namespace (if that makes sense?)

@ryandesign
Copy link

I don't think you want to use the flat namespace. That's a relic from the days of Mac OS X 10.0 and 10.1. It was superseded by the two-level namespace in Mac OS X 10.2.

@martin-frbg
Copy link
Collaborator

Thanks for the explanation. I wonder if this still allows overloading XERBLA with a user-supplied version though (not sure who uses this outside some of the included tests, but it is part of established BLAS/LAPACK behaviour)

@martin-frbg martin-frbg added this to the 0.3.26 milestone Jan 2, 2024
@martin-frbg martin-frbg merged commit 8278d0d into OpenMathLib:develop Jan 2, 2024
64 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants