Skip to content

Commit

Permalink
Add the RTLD_NODELETE flag to dlopen (#1030)
Browse files Browse the repository at this point in the history
### Before submitting

Please complete the following checklist when submitting a PR:

- [ ] All new features must include a unit test.
If you've fixed a bug or added code that should be tested, add a test to
the
      [`tests`](../tests) directory!

- [ ] All new functions and code must be clearly commented and
documented.
If you do make documentation changes, make sure that the docs build and
      render correctly by running `make docs`.

- [ ] Ensure that the test suite passes, by running `make test`.

- [x] Add a new entry to the `.github/CHANGELOG.md` file, summarizing
the
      change, and including a link back to the PR.

- [x] Ensure that code is properly formatted by running `make format`. 

When all the above are checked, delete everything above the dashed
line and fill in the pull request template.


------------------------------------------------------------------------------------------------------------

**Context:**

There are segfault issue for finite-shot hermitians tests with Catalyst
on arm64-macos. It looks like closing `libscipy_openblas.dylib` has a
side effect that leads to the segfault and using `RTLD_NODELETE`
mitigates that.

**Description of the Change:**

**Benefits:**

**Possible Drawbacks:**

**Related GitHub Issues:**
[sc-80901]

---------

Co-authored-by: ringo-but-quantum <github-ringo-but-quantum@xanadu.ai>
  • Loading branch information
multiphaseCFD and ringo-but-quantum authored Dec 18, 2024
1 parent 9f3cf06 commit 11b03d4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@

### Bug fixes

* Add `RTLD_NODELETE` flag to `dlopen` in order to mitigate the segfault issues for arm64-macos Catalyst support.
[(#1030)](https://github.com/PennyLaneAI/pennylane-lightning/pull/1030)

* Set rpath with `@loader_path` instead of `$ORIGIN` for macOS.
[(#1029)](https://github.com/PennyLaneAI/pennylane-lightning/pull/1029)

Expand Down
2 changes: 1 addition & 1 deletion pennylane_lightning/core/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
Version number (major.minor.patch[-label])
"""

__version__ = "0.40.0-dev40"
__version__ = "0.40.0-dev41"
5 changes: 4 additions & 1 deletion pennylane_lightning/core/src/utils/SharedLibLoader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ class SharedLibLoader final {
public:
SharedLibLoader();
explicit SharedLibLoader(const std::string &filename) {
handle_ = PL_DLOPEN(filename.c_str(), RTLD_LAZY);
// NOTE: RTLD_NODELETE flag is a temporary solution. It could be
// problematic if the shared library is not static stored in memory and
// runtime unloaded is needed. Come back to this later.
handle_ = PL_DLOPEN(filename.c_str(), RTLD_LAZY | RTLD_NODELETE);
PL_ABORT_IF(!handle_, PL_DLERROR());
}

Expand Down

0 comments on commit 11b03d4

Please sign in to comment.