bogo / arm64-to-sim

Transmogrify native iOS frameworks to run in iOS Simulator on Apple silicon.
https://bogo.wtf/arm64-to-sim.html
MIT License
539 stars 86 forks source link

Invalid arm64 header type #21

Open rafaelbaraldi opened 1 year ago

rafaelbaraldi commented 1 year ago

Hi,

First of all, thank you for this script and for the explanation at the blog! I do not understand why Apple doesn't let you link device arm64 binaries for simulador arm64 version :(

Well, my problem here is that I'm getting this error below:

Arm64ToSimLib/Transmogrifier.swift:49: Fatal error: The file is not a correct arm64 binary. Try thinning (via lipo) or unarchiving (via ar) first.

I was using a static library that is a fat binary containing armv7, armv7s, i386, x86_64 and arm64 architectures, let's call it "library.a". lipo -info library.a Architectures in the fat file: library.a are: armv7 armv7s i386 x86_64 arm64

As the error above indicates, I tried to extract from this library only the arm64 slice. I tried it with lipo -extract and also with lipo -thin. Both cases generated me a new library with only arm64 architecture. But it still shows me the same error. I also tried unarchiving the static library object and generating a new library with only arm64 using ar command as follows but it didn't work either:

lipo -extract arm64 library.a -o newLibrary.a

lipo library.a -thin arm64 -output newLibrary.a

ar -xv library.a; ar -rc newLibrary.a *.o

I edited de code for arm64-to-sim binary to print the mach_header_64 properties, the result is the following: header: mach_header_64(magic: [1918975009](tel:1918975009), cputype: 171862115, cpusubtype: 841953571, filetype: 538976304, ncmds: 538976288, sizeofcmds: 538976288, flags: 926430769, reserved: 892941365)

I was not able to match this values with any static value from Swift MachO library like CPU_TYPE_ARM64 that is expected in this script.

Am I missing something here? Should I be using a different kind of binary files for this script?

Again, thank you so much for your help. This behavior should be de default for Apple stuff, I’m tired to see answers like remove arch arm64 for simulador or to use Rosetta 2.

rafaelbaraldi commented 1 year ago

Ok, now I understand that I actually need to pass each individual .o objects as parameters to the Transmogrifier code after I unarchive then from the static library. But still getting the same error of incorrect arm64 binary.

Following your steps as the blog describes I notice that using otool -l in my original library did not print any kind of load comand “cmd” 🤔