Determine the file architecture for binary files
This post is a quick write up of something that came up recently. At $DAY_JOB
we were playing around with Google Codelabs and using the claat
tool, which comes with releases for several different operating systems.
I ended up sharing some lower-level knowledge that may not be obvious given that so many apps are multi platform these days. Also, fun fact, learned about this tips when I was testing WAS as an intern, back when we used to ship software on CDs. (Very much dating myself here)
Error messages
The first hint that you’re running something on the wrong platform is that it bombs out immediately with a very unhelpful error message, like when you run a Linux binary running on macOS. What the heck is an exec format error
?!
$ ./claat-linux
zsh: exec format error: ./claat-linux
Finding what OS it should run on
A quick way to verify if the binary you’re running will work on your system is with the file
command. Here’s the output for both the MacOS and Linux versions of claat
.
$ file claat
claat: Mach-O 64-bit executable x86_64
$ file claat-linux
claat-linux: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, stripped
The Mach-0 and ELF bits are what give it away. ELF means that it runs on Unix-like OS’s, whereas Mach-0 indicates that it runs on MacOS and other Apple OS’s.
This Wiki article has a comprehensive list of file formats with additional information.