Skip to content

Feature Request: Do not reuse different architecture version of temporary APE Loader on Darwin #1409

@BenceSzalai

Description

@BenceSzalai

Note

Not sure, it may be better suited to be raised as a bug...

Prerequisites

  • I am running the latest code. Mention the version if possible as well.
  • I carefully followed the README.md.
  • I searched using keywords relevant to my issue to make sure that I am creating a new issue that is not already open (or closed).
  • I reviewed the Discussions, and have a new and useful enhancement to share.

Feature Description

When a cosmo app is started it creates a /private/var/folders/bq/<long_string_of_characters_and_numbers>/T/.ape-1.10 file, which will be executed for the application runtime.

This file should be created using a name, that includes architecture, e.g.:
/private/var/folders/bq/<long_string_of_characters_and_numbers>/T/.ape-1.10-x86_64
/private/var/folders/bq/<long_string_of_characters_and_numbers>/T/.ape-1.10-arm64

Motivation

I've encountered an issue which took quite some time to overcome, you can see the details in Mozilla-Ocho/llamafile#750

Long story short, the problem is that on Darwin systems running on ARM with Rosetta it is possible to launch a cosmo application both in ARM and Intel mode. Cosmo apparently decides which version of .ape it creates only on first launch, and reuses the already present version on any subsequent launches.

Which means that if someone kicks of a cosmo app in x86_64 mode, they will end up with:

> file .ape-1.10
.ape-1.10: Mach-O 64-bit executable x86_64

Whereas if they start a cosmo app in ARM mode, they will end up with:

> file .ape-1.10
.ape-1.10: Mach-O 64-bit executable arm64

Problem arises when someone is trying to switch between Rosetta and native or if they use multiple cosmo apps, some with Rosetta and some in native ARM mode. Based on which mode they started first, all other cosmo app will also run either as x86_64 or arm. This can give the very puzzling experience that even arch -arm64 ./someapp results in an x86_64 process, or arch -x86_64 ./someapp results in an arm64 process.

I guess a naive solution could be to always rewrite .ape with the correct version, but that would still prevent someone to run cosmo apps concurrently with different architecture.

If the .ape file name included the architecture, this would be just fine.

Info:

Cosmopolitan versions effected and tested: v3.9.7, v4.0.2
Platform: Darwin 24.4.0, macOS v15.4.1 /w Rosetta on Apple Silicon

UPDATE:

I think this last title of this issue expresses the intetion best.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions