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

Update for building on modern systems, including Apple Silicon #2

Merged
merged 6 commits into from
Feb 19, 2025

Conversation

Sorixelle
Copy link
Member

This PR is an upstream of the patches in https://github.com/Sorixelle/pebble.nix/tree/main/derivations/pebble-qemu that allow this repo to be built, and the resulting binaries to be run on modern systems, particularly Apple Silicon macOS systems. All of this is generally useful outside of a Nix environment, so it would be nice to have here so anyone can build this repo easily if they need to.

@Sorixelle
Copy link
Member Author

It's probably worth tagging this as 2.5.0-pebble5 if merged - should I update the version in this commit or will that happen after this is merged?

macOS on Apple Silicon does not allow memory pages to be marked as RWX. Instead,
to achieve the same behaviour, pages be allocated with the MAP_JIT flag, and the
permissions are dynamically switched between RW and RX using the
pthread_jit_write_protect function.[1]

Most of this commit is derived from upstream work in [2], with changes as
necessary to apply onto this older tree.

[1]: https://developer.apple.com/documentation/apple-silicon/porting-just-in-time-compilers-to-apple-silicon
[2]: https://gitlab.com/qemu-project/qemu/-/commit/653b87eb36045b506b79f0bb433016ef1c54bc9a

Signed-off-by: Ruby Iris Juric <[email protected]>
At some point, sys/memfd.h was removed from most systems.[1] Instead, the
definitions we need from it can now be found in sys/mman.h.

[1]: https://stackoverflow.com/questions/56615488/getting-gcc-error-sys-memfd-h-no-such-file-or-directory

Signed-off-by: Ruby Iris Juric <[email protected]>
Without these includes, the build fails on some systems due to missing
declarations for qemu_system_reset_request, which live in sysemu/sysemu.h.

Signed-off-by: Ruby Iris Juric <[email protected]>
Similarly to 745fb61, it seems some definitions may have been moved around in
the C stdlib, and accessing major requires explicitly including sys/sysmacros.h.

Signed-off-by: Ruby Iris Juric <[email protected]>
Somewhere in the macOS build, there's an #include for <version>. Because the
root source directory is added to the include path during build, that include
picks up this VERSION file, which makes the build fail since it doesn't contain
valid C code. Renaming the file to prevent the name collision allows the build
to proceed as normal.

Signed-off-by: Ruby Iris Juric <[email protected]>
All of the old submodules are currently dead, either because of dropping support
for the old git:// scheme (like GitHub), or because the repos have been moved to
a new location.

Signed-off-by: Ruby Iris Juric <[email protected]>
@Sorixelle Sorixelle force-pushed the modern-build-support branch from cff84e6 to 6b5da58 Compare February 19, 2025 08:15
@Hexxeh
Copy link

Hexxeh commented Feb 19, 2025

Works for me. We'd have to create and push a new tag after this is merged.

Also we might want to mention that unlike the FW, Python 2 is required to build this.

@Sorixelle
Copy link
Member Author

It should be pretty trivial to port these scripts to Python 3, especially since there's no external dependencies - 2to3 should do the trick. I'll put that on the list of things to do at some point. Good callout, thanks!

@Sorixelle Sorixelle merged commit 3b61367 into pebble-dev:master Feb 19, 2025
1 check passed
@Sorixelle Sorixelle deleted the modern-build-support branch February 19, 2025 10:40
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.

2 participants