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

regopy does not work on ARM #92

Open
aquamatthias opened this issue Dec 18, 2023 · 8 comments
Open

regopy does not work on ARM #92

aquamatthias opened this issue Dec 18, 2023 · 8 comments
Assignees
Labels
bug Something isn't working

Comments

@aquamatthias
Copy link
Contributor

Installing regopy on ARM architecture works, but using it throws an error.

▶ pip install regopy  
Collecting regopy
  Using cached regopy-0.3.10-cp311-cp311-macosx_11_0_arm64.whl.metadata (7.9 kB)
Using cached regopy-0.3.10-cp311-cp311-macosx_11_0_arm64.whl (7.8 MB)
Installing collected packages: regopy
Successfully installed regopy-0.3.10

▶ python3                        
Python 3.11.6 (main, Dec  4 2023, 18:49:48) [Clang 15.0.0 (clang-1500.0.40.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from regopy import Interpreter
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/matthias/Documents/Work/someeng/resoto/venv/lib/python3.11/site-packages/regopy/__init__.py", line 5, in <module>
    from ._regopy import (
ImportError: dlopen(/Users/matthias/Documents/Work/someeng/resoto/venv/lib/python3.11/site-packages/regopy/_regopy.cpython-311-darwin.so, 0x0002): tried: '/Users/matthias/Documents/Work/someeng/resoto/venv/lib/python3.11/site-packages/regopy/_regopy.cpython-311-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/matthias/Documents/Work/someeng/resoto/venv/lib/python3.11/site-packages/regopy/_regopy.cpython-311-darwin.so' (no such file), '/Users/matthias/Documents/Work/someeng/resoto/venv/lib/python3.11/site-packages/regopy/_regopy.cpython-311-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))
@matajoh matajoh self-assigned this Jan 18, 2024
@matajoh matajoh added the bug Something isn't working label Jan 18, 2024
@matajoh
Copy link
Member

matajoh commented Jan 18, 2024

Thanks for the report! Looks like cross-compile isn't working properly. I'll dig into it.

@matajoh
Copy link
Member

matajoh commented Jan 19, 2024

It would be hugely helpful if you would try building the python module locally on the hardware. You can do this in the following way:

  1. Ensure you have cmake installed along with an appropriate compiler (it will need to be able to link against the libpython headers/libraries)
  2. In the wrappers/python directory, run python setup.py bdist_wheel (or alternatively pip install -e . to get a purely local build)

If that works and the resulting python module is able to be used, then that would definitely nail it down as a cross-compile problem. No worries if you can't, but it would help provide some information while I try to get my hands on some ARM hardware to build and test on.

@matajoh
Copy link
Member

matajoh commented Jan 22, 2024

I've upgraded our CI to use the new Github M1 runners to build arm64 wheels. If you were able to try one of those and see if it resolves your issue, that would be greatly appreciated.

@aquamatthias
Copy link
Contributor Author

@matajoh Thanks for digging into this. I tested the latest state on my M1 machine, and everything works fine.
The issue can be closed from my POV.

@aquamatthias
Copy link
Contributor Author

And no: I see this in the console after I copy/pasted the example:

Python(16846,0x1e3dc1000) malloc: *** error for object 0x104f299c0: pointer being freed was not allocated
Python(16846,0x1e3dc1000) malloc: *** set a breakpoint in malloc_error_break to debug
[1]    16846 abort      python3

@matajoh
Copy link
Member

matajoh commented Jan 23, 2024

Fun! Looks like there is some Arm64 Python specific issue causing a double free in the Python runtime. Unfortunately as I do not have local access to an Apple Silicon machine it is going to make debugging this quite difficult. Out of curiosity, would you please paste the entire output of the console when running the test script with the "-v" option? It may help me nail down exactly what problem Python is having in this circumstance while I try to track down a machine I can actually debug this on.

@anakrish
Copy link

I happen to run into the pointer being freed was not allocated issue as well. https://github.com/anakrish/rego-compare/blob/faf002f611e1ced7c7eb3a687e8b542b86f74bc6/compare#L74

It can be reproduced by doing a strip

~/r/r/build (main) [106]> dist/bin/rego
rego 0.3.11 (main:6d84fc7, Fri, 19 Jan 2024 17:29:17 +0000)[AppleClang 15.0.0.15000100] on macos
--query is required
Run with --help or --help-all for more information.
~/r/r/build (main) [106]> strip dist/bin/rego
~/r/r/build (main)> dist/bin/rego
rego 0.3.11 (main:6d84fc7, Fri, 19 Jan 2024 17:29:17 +0000)[AppleClang 15.0.0.15000100] on macos
--query is required
Run with --help or --help-all for more information.
rego(5263,0x1dbe59000) malloc: *** error for object 0x106329980: pointer being freed was not allocated
rego(5263,0x1dbe59000) malloc: *** set a breakpoint in malloc_error_break to debug
fish: Job 1, 'dist/bin/rego' terminated by signal SIGABRT (Abort)

I couldn't debug it much since there aren't any debug symbols, but I was to bisect the code and figure out that the issue happens once line 43 has executed:

auto interpreter = rego::Interpreter();

Using dsymutil allowed retaining symbols yet reproduce the issue.

Hope this helps.

@matajoh
Copy link
Member

matajoh commented Jan 24, 2024

I've added the Apple Silicon build machines to our CI in an attempt to repro this error but it doesn't seem to arise on that hardware for any of those tests, which include building and running the Python wrapper and testing it (in addition to all the C, C++, and Rust tests). I'll see if I can get access to an arm Mac so I can try to repro what you have here @anakrish.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants