Incorrect Registers Values with Rosetta 2

#include <stdio.h>

int main() {
  unsigned long a, d;
  __asm__ volatile (
    "\n\t" 
    "movl $0x77777777, %%eax\n\t"
    "movl $0xffffffff, %%ecx\n\t"
    "xorl %%edx, %%edx\n\t"
    "divl %%ecx\n\t"
    "cwtd\n\t"
    "movq %%rax, %0\n\t"
    "movq %%rdx, %1\n\t"
    : "=r"(a), "=r"(d)
    :: "rax", "rdx"
  );

  printf("rax: %lx, rdx, %lx", a, d);
}

The minimal program above was expected to give rax: 0, rdx: 77770000 but on macOS with Rosetta 2 it gave rax: 0, rdx, 0. It causes specfic programs (e.g. Genshin Impact) to crash.

Post not yet marked as solved Up vote post of Waterlens Down vote post of Waterlens
1.2k views

Replies

causes specfic programs (e.g. Genshin Impact) to crash.

It sounds like your goal is to file a bug, in which case I recommend that you do that using Feedback Assistant. See my Bug Reporting: How and Why? post for all the details.

Please post your bug number, just for the record.

Having said that, remember that Rosetta is a compatibility feature and the best way to get around such problems is to port your code to run natively.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Thank you for your reply.

For your information, the bug number is FB13503265. Unluckily, it's impossible for me to port a third-party program.

Seems that this has been fixed in macOS 14.4 Beta (23E5180j).