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

Fix stack alignment and auxv for APE loader on macOS #931

Merged
merged 1 commit into from
Nov 5, 2023
Merged

Conversation

ghaerr
Copy link
Sponsor Contributor

@ghaerr ghaerr commented Nov 5, 2023

Hi @jart,

Through extensive testing on another project, I have found that the Cosmopolitan APE loader sometimes crashes with SIGSEGV on x86_64 macOS for two reasons: 1) the startup stack pointer isn't automatically aligned by the kernel (it varies based on passed argv/envp strings), and 2) the macOS auxv vector isn't ELF compatible; they're passed as a pointer array similar to char **environ, rather than an ELF-compatible twin-pointer array. Depending on the arguments passed to the loader, the stack misalignment can cause a crash very early in startup.S when calling the loader entry point ApeLoader, or later, when the aux vector is assumed to be ELF-compatible.

These fixes (with the exception of the ARM64 startup) have been tested on macOS Mojave and Catalina using the loader in another project. I am unable to test on the latest Cosmopolitan tree, as build/bootstrap/make.com immediately segfaults, the reason for which is almost assuredly this same problem. After this fix is incorporated and make.com updated, I will test the Cosmopolitan build and report further.

Thank you!

Copy link
Owner

@jart jart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find. Thanks!

@jart jart merged commit 4f100d2 into jart:master Nov 5, 2023
G4Vi pushed a commit to G4Vi/cosmopolitan that referenced this pull request Jan 19, 2024
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