Running x86-64 on an ARM Mac

I have an ARM Mac and whilst trying to run hello-world locally, I get an error:

ld: warning: no platform load command found in '/Users/erik/solutions/x86-64-assembly/hello-world/hello_world.o', assuming: macOS
ld: fatal warning(s) induced error (-fatal_warnings)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [tests] Error 1

I’ve followed the steps listed in the docs: Installing x86-64 Assembly locally | Exercism's Docs

Any thoughts?

I could easily be wrong but I didnt imagine an ARM64 mac could run x86-64??

I’m thinking I’ll try working with a docker container when it’s November rolls around instead?

Yeah I was double-checking. It might be nicer to fail explicitly from within the Makefile with a nice error message.

1 Like

M1/2 support compiling and running x86_64 code natively, and the exercism Makefile addresses it (see the arm64 check at line 8). The problem you’re facing is related to the linker changes in Ventura+. The simplest workaround is to switch to the old linker for the time being, by adding -Wl,-ld_classic to ALL_LDFLAGS (on line 11 as of now).

Some explanation: the linker now requires the load command LC_BUILD_VERSION to be present in the object file, which specifies target (macOS, iOS, etc) and version. NASM currently doesn’t support it, there was a patch for it, but it’s not in the upstream.

3 Likes

this is what I get with added suggested flags when trying to compile leap exercise

make clean && make
rm -f *.o vendor/*.o tests
cc -target x86_64-apple-darwin -std=c99 -fPIE -m64 -g -Wall -Wextra -pedantic -Werror -c -o leap_test.o leap_test.c
nasm -f macho64 --prefix _ -g -F dwarf -Werror -o leap.o leap.asm
cc -target x86_64-apple-darwin -std=c99 -fPIE -m64 -g -Wall -Wextra -pedantic -Werror -c -o vendor/unity.o vendor/unity.c
cc -target x86_64-apple-darwin -std=c99 -fPIE -m64 -g -Wall -Wextra -pedantic -Werror -Wl,-pie -Wl,-fatal_warnings -Wl,-ld_classic  -o tests leap_test.o leap.o vendor/unity.o
./tests
make: ./tests: Bad CPU type in executable
make: *** [all] Error 1

Compilation exited abnormally with code 2 at Sun Nov  5 21:36:19

I have M2 with Sonoma 14.0

I was able to execute tests by right clicking the terminal in Application/Utilities, clicking get info then on general section checking the option open using Rosetta.
The first time using rosetta will pop up a window to install it.
Apparently this rosetta will run the app in compatibility mode, if you open the terminal and type arch the command should return i386.

at the end of execution it is happening a segfault, but tests are finished by that point.

@RedJocker yes, you need to have Rosetta 2 installed in order to run x86_64 binaries. After you install it, it should work seamlessly (maybe login/logout or reboot just to be sure).

It’s strange that you have a segfault, maybe there is an issue with your implementation? Does it happen with hello-world?

Also, it might be worth trying replacing the line above (with -target) too. On my machine I apply the following patch after pulling in an exercise:

diff -uU0 old/Makefile new/Makefile
--- old/Makefile	2023-11-12 12:31:12
+++ new/Makefile	2023-11-12 12:31:04
@@ -9 +9 @@
-	ALL_CFLAGS = -target x86_64-apple-darwin
+	ALL_CFLAGS = -arch x86_64
@@ -11 +11 @@
-	ALL_LDFLAGS = -Wl,-pie -Wl,-fatal_warnings
+	ALL_LDFLAGS = -Wl,-pie -Wl,-fatal_warnings -Wl,-ld_classic