cosmopolitan: Hello.com, redbean.com fail to run on MacOS M1 under Rosetta

hello.com is built on linux following instructions published here: https://justine.lol/cosmopolitan/ and then executed on a MacBook Pro with the M1 Max chip (arm64) running macOS Monterey 12.4 under Rosetta translation.

#To confirm that it's running under Rosetta:
❯ arch -arch x86_64 ./[hello.com](http://hello.com/)
[1]    79473 segmentation fault  arch -arch x86_64 ./[hello.com](http://hello.com/)

❯ sh ./[hello.com](http://hello.com/)
[1]    73377 segmentation fault  sh ./[hello.com](http://hello.com/)
❯ sh ./[hello.com](http://hello.com/) --assimilate
❯ ./[hello.com](http://hello.com/)
[1]    73395 segmentation fault  ./[hello.com](http://hello.com/)
❯ lldb --file ./[hello.com](http://hello.com/)
(lldb) target create "./[hello.com](http://hello.com/)"
Current executable set to '/Users/user/cosmo/[hello.com](http://hello.com/)' (x86_64).
(lldb) r
Process 73409 launched: '/Users/user/cosmo/[hello.com](http://hello.com/)' (x86_64)
Process 73409 stopped
* thread #1, stop reason = EXC_BAD_ACCESS (code=1, address=0x1f)
    frame #0: 0x000000000040239f [hello.com](http://hello.com/)
->  0x40239f: movl   (%rsp), %ebx
    0x4023a2: leaq   0x8(%rsp), %rsi
    0x4023a7: leaq   0x10(%rsp,%rbx,8), %rdx
    0x4023ac: movq   %rsp, 0x1e97d(%rip)
Target 0: ([hello.com](http://hello.com/)) stopped.
(lldb) bt
* thread #1, stop reason = EXC_BAD_ACCESS (code=1, address=0x1f)
  * frame #0: 0x000000000040239f [hello.com](http://hello.com/)
(lldb)
❯ file [hello.com](http://hello.com/)
[hello.com](http://hello.com/): Mach-O 64-bit executable x86_64

Full crash report:

{"app_name":"[hello.com](http://hello.com/)","timestamp":"2022-06-17 12:25:25.00 -0700","app_version":"","slice_uuid":"45e417b7-2c6d-a6da-45e4-17b72c6da6da","build_version":"","platform":0,"share_with_app_devs":1,"is_first_party":1,"bug_type":"309","os_version":"macOS 12.4 (21F79)","incident_id":"E185D602-4547-4382-874C-6A44AF63AAD3","name":"[hello.com](http://hello.com/)"}
{
  "uptime" : 2300000,
  "procLaunch" : "2022-06-17 12:25:25.2262 -0700",
  "procRole" : "Unspecified",
  "version" : 2,
  "userID" : 501,
  "deployVersion" : 210,
  "modelCode" : "MacBookPro18,4",
  "procStartAbsTime" : 55200184527962,
  "coalitionID" : 3240,
  "osVersion" : {
    "train" : "macOS 12.4",
    "build" : "21F79",
    "releaseType" : "User"
  },
  "captureTime" : "2022-06-17 12:25:25.4489 -0700",
  "incident" : "E185D602-4547-4382-874C-6A44AF63AAD3",
  "bug_type" : "309",
  "pid" : 73395,
  "procExitAbsTime" : 55200189857901,
  "translated" : true,
  "cpuType" : "X86-64",
  "procName" : "[hello.com](http://hello.com/)",
  "procPath" : "\/Users\/USER\/*\/[hello.com](http://hello.com/)",
  "parentProc" : "zsh",
  "parentPid" : 73319,
  "coalitionName" : "com.googlecode.iterm2",
  "crashReporterKey" : "917168CC-9F91-8E09-0E83-6F8C1759F8E6",
  "responsiblePid" : 10569,
  "responsibleProc" : "iTerm2",
  "wakeTime" : 29832,
  "sleepWakeUUID" : "5126274E-4713-4921-8ECB-404A80F155BC",
  "sip" : "enabled",
  "vmRegionInfo" : "0x1f is not in any region.  Bytes before following region: 140718563835873\n      REGION TYPE                    START - END         [ VSIZE] PRT\/MAX SHRMOD  REGION DETAIL\n      UNUSED SPACE AT START\n--->  \n      mapped file              7ffb9802c000-7ffbc5b10000 [730.9M] r-x\/r-x SM=COW  ...t_id=a25954a5",
  "isCorpse" : 1,
  "exception" : {"codes":"0x0000000000000001, 0x000000000000001f","rawCodes":[1,31],"type":"EXC_BAD_ACCESS","signal":"SIGSEGV","subtype":"KERN_INVALID_ADDRESS at 0x000000000000001f"},
  "termination" : {"flags":0,"code":11,"namespace":"SIGNAL","indicator":"Segmentation fault: 11","byProc":"exc handler","byPid":73395},
  "vmregioninfo" : "0x1f is not in any region.  Bytes before following region: 140718563835873\n      REGION TYPE                    START - END         [ VSIZE] PRT\/MAX SHRMOD  REGION DETAIL\n      UNUSED SPACE AT START\n--->  \n      mapped file              7ffb9802c000-7ffbc5b10000 [730.9M] r-x\/r-x SM=COW  ...t_id=a25954a5",
  "extMods" : {"caller":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"system":{"thread_create":0,"thread_set_state":1,"task_for_pid":2},"targeted":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"warnings":0},
  "usedImages" : [
  {
    "size" : 0,
    "source" : "A",
    "base" : 0,
    "uuid" : "00000000-0000-0000-0000-000000000000"
  }
],
  "legacyInfo" : {
  "threadHighlighted" : 0
},
  "trialInfo" : {
  "rollouts" : [
    {
      "rolloutId" : "6112e14f37f5d11121dcd519",
      "factorPackIds" : {
        "SIRI_TEXT_TO_SPEECH" : "629e5353a0d1644ed53959b8"
      },
      "deploymentId" : 240000148
    },
    {
      "rolloutId" : "61301e3a61217b3110231469",
      "factorPackIds" : {
        "SIRI_FIND_MY_CONFIGURATION_FILES" : "6216ae152a40e71046e16225"
      },
      "deploymentId" : 240000016
    }
  ],
  "experiments" : [

  ]
},
  "reportNotes" : [
  "_dyld_process_info_create failed with 5",
  "dyld_process_snapshot_get_shared_cache failed",
  "Failed to create CSSymbolicatorRef - corpse still valid ¯\\_(ツ)_\/¯"
]
}

@jart, is there any additional information I can get to troubleshoot this? --ftrace doesn’t show any information at all, so it appears to be crashing before it gets to any of the function frames.

It may be related to AVX instruction support (even though EXC_BAD_ACCESS seems to indicate a memory issue); Rosetta documentation indicates the following:

Rosetta translates all x86_64 instructions, but it doesn’t support the execution of some newer instruction sets and processor features, such as AVX, AVX2, and AVX512 vector instructions. If you include these newer instructions in your code, execute them only after verifying that they are available. For example, to determine if AVX512 vector instructions are available, use the sysctlbyname function to check the hw.optional.avx512f attribute.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 22 (19 by maintainers)

Commits related to this issue

Most upvoted comments

Thanks!

PR opened, just had to make a minor tweak to your simplified patch - it looks like we can’t avoid clearing %rcx in loader-macho and loader-elf without having a segfault, so added that one back in, and same with %rdi in crt.S so we don’t erroneously pass the FreeBSD check (as %rdi is also non-zero under Rosetta, as it is on FreeBSD).

Tested the PR against hello.com, standalone ape, and redbean.com on M1 and all appears to be working.

As a simpler hack, adding:

mov $0, %rdi
mov $XNU,%cl

immediately under _start: in crt.S (and still stubbing out OverlapsShadowSpace) also leads us to a working hello world (only on an assimilated binary).