bloomberg / memray

Memray is a memory profiler for Python
https://bloomberg.github.io/memray/
Apache License 2.0
13.17k stars 392 forks source link

Fix a segfault on macOS when _dyld_shared_cache_contains_path is not available #615

Closed pablogsal closed 4 months ago

pablogsal commented 4 months ago

The _dyld_shared_cache_contains_path is only available in macOS 11.0 or later. As we are compiling in a new system that's newer than 11.0 but setting the deployment target to an older version, it's possible that the _dyld_shared_cache_contains_path is not available in the target platform and in that case we will segfault when calling it. It's also possible that when compiling memray in an old system _dyld_shared_cache_contains_path is not even prototyped in the headers.

To handle this, we change to fetch the function via a dlopen/dlsym approach that will be generic in all macOS versions at the cost of an extra call to dlopen the first time we interpose symbols.

codecov-commenter commented 4 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 92.97%. Comparing base (41248ed) to head (a347134). Report is 72 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #615 +/- ## ========================================== + Coverage 92.55% 92.97% +0.42% ========================================== Files 91 92 +1 Lines 11304 11323 +19 Branches 1581 2076 +495 ========================================== + Hits 10462 10528 +66 + Misses 837 795 -42 + Partials 5 0 -5 ``` | [Flag](https://app.codecov.io/gh/bloomberg/memray/pull/615/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bloomberg) | Coverage Δ | | |---|---|---| | [cpp](https://app.codecov.io/gh/bloomberg/memray/pull/615/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bloomberg) | `92.97% <ø> (+7.03%)` | :arrow_up: | | [python_and_cython](https://app.codecov.io/gh/bloomberg/memray/pull/615/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bloomberg) | `92.97% <ø> (-2.75%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bloomberg#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.