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

Allow replacing jartsr= magic with #!/bin/sh header #1181

Open
supriyo-biswas opened this issue May 19, 2024 · 0 comments
Open

Allow replacing jartsr= magic with #!/bin/sh header #1181

supriyo-biswas opened this issue May 19, 2024 · 0 comments

Comments

@supriyo-biswas
Copy link

supriyo-biswas commented May 19, 2024

Because of how APE binaries are designed, they are not natively executable using exec*() syscalls and require invocation from a shell.

While this can be worked around with assimilate, there are two major issues with this approach:

  1. This breaks user expectations for a "self contained", "no installation required" binary artifact.
  2. assimilate strips support for other platforms, thus requiring the software distributor to have multiple binaries for different platforms, thus negating the use case for cosmopolitan.

Therefore, there should be a way to emit a binary artifact with a standard #!/bin/sh header such that portability is maintained for MachO + Linux + BSD platforms.

Although I'm not familiar with the codebase, as I understand, there are two things that would need to be done to implement this:

1 #!/bin/sh is longer than the current magic. To prevent complicating the codebase with conditional offset generation when this option is enabled, extend the default magic headers in apelink.c by some additional bytes such that the executable nature of the PE binaries and the magic header string is preserved, for example, MZqFpD='\n[...] would become `MZqFpD='\nxxx[...]"
2. Modify the detection logic in loader.c to pick up on this new "shell-script but actually APE" binaries.
3. Modify ape.S to use the new magic.

Thanks!

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

No branches or pull requests

1 participant