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

Add support for FreeBSD #593

Closed
1 task done
mohd-akram opened this issue May 11, 2024 · 2 comments
Closed
1 task done

Add support for FreeBSD #593

mohd-akram opened this issue May 11, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@mohd-akram
Copy link

Is there an existing proposal for this?

  • I have searched the existing proposals

Is your feature request related to a problem?

Currently, trying to install this on FreeBSD 14 yields RuntimeError: memray does not support this platform (freebsd14). I'm not sure if it requires anything specific from FreeBSD, but BSDs are similar to macOS.

Describe the solution you'd like

Support for FreeBSD

Alternatives you considered

No response

@mohd-akram mohd-akram added the enhancement New feature or request label May 11, 2024
@godlygeek
Copy link
Contributor

godlygeek commented May 11, 2024

Well, PyPI doesn't allow pre-built wheels for BSDs, so there's no way we could possibly give first class support for them. If you'd be interested in porting Memray to FreeBSD, we'd be willing to accept patches for that, if they were small enough and unobtrusive enough. You could start by cloning the repo, deleting the line giving that error from the setup.py, and seeing what fails next. Our GitHub Actions workflows and cibuildwheel configuration should give a decent overview of what our native build dependencies are on each Linux distro we build on, and on macOS.

The hardest parts to port by far will be support for memray run --native, and support for intercepting malloc calls.

  1. You'll need a way to iterate over all of the shared libraries that have been loaded in the process's address space. Memray uses dl_iterate_phdr for that on Linux, and uses _dyld_get_image_header for it on macOS. FreeBSD would need some API that can be used to do the equivalent.
  2. You need a way to intercept calls to malloc in each of those shared libraries. Conceptually this is "just" patching the Procedure Linkage Table, but the way to do that is platform dependent. The files linked above are Memray's implementation of this for Linux (ELF) and macOS (machO). FreeBSD seems to use ELF, so the Linux implementation may be close to right for FreeBSD.
  3. You'll need an unwinder to unwind native stacks (we use libbacktrace on Linux, I'm not sure if it supports FreeBSD or not).
  4. You'll need a way to symbolify native symbols (we use libdw and libelf from elfutils to do this on Linux).

At a glance, it seems like dl_iterate_phdr might exist on FreeBSD, so if elfutils and libbacktrace support FreeBSD, this might "just" require an implementation of the PLT patching that works for FreeBSD, and otherwise treating FreeBSD like Linux everywhere that we've got platform-specific conditionals.

Since none of the maintainers of this project use FreeBSD, we're highly unlikely to ever do this work ourselves. If you're interested in doing the porting, we can answer questions to help guide you along, and unstick you if you get stuck. If you're not interested in being the one to do that porting, we'll just close this issue. This isn't something we're ever likely to do ourselves.

@godlygeek
Copy link
Contributor

godlygeek commented May 30, 2024

I'm going to close this for now, since I haven't heard anyone volunteer to do this work yet.

If anyone wants to try to take it on, feel free to reach out for help or advice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants