Skip to content
Advertisement

How to get the correct binary for my architecture. Trying to run ARM (.s) files

I’ve used the following commands for cross-compilation on ubuntu to run simple.s but am getting an error

JavaScript

The commands are:

JavaScript

I tried to obtain the binary’s architecture by

JavaScript

and my machine’s architecture by

JavaScript

and found that they were different. I believe getting the right binary for the architecture will solve the problem. Is that true?

Here is simple.s

JavaScript

How can this issue be solved? Thx

Advertisement

Answer

You cannot natively execute a Linux executable compiled for a 32 bit ARM Linux system on a x86_64 Linux PC, because there are using different processors designed by different companies and, more importantly, using different instruction sets with different programming models.

For example, if you compile this simple C program with arm-linux-gnueabi-gcc, the compiler will generate the following ARM assembly code:

add.c:

JavaScript

add.s:

JavaScript

Now, if you compile it with x86_64-linux-gnu-gcc, it will generate code for the x86_64/amd64 architecture:

add.s:

JavaScript

As you can see, the assembly is completely different, as will be the generated machine code once they will have been assembled and linked. Reading the section titled ‘Long Answerhere will make it obvious.

Different architectures means different CPU: arm-linux-gnueabi-as can only compile programs for and ARM CPU without hardware support for floating point operations running Linux: there is a hint in the compiler name, which is build from the architecture, operating system, and ABI it can compile programs for:

[arm]-[linux]-[gnueabi] , or [x86_64]-[linux]-[gnu] for example. See here for a short explanations of what ‘target triplets’ are in the context of the gcc compiler.

Cross-compiling is the action of compiling a program targeting a computer with CPU cpu#1 running operating system os#1 on a different computer with CPU cpu#2 running operation system os#2.

In your case, you are compiling a program designed for running on a 32 bit ARM CPU running Linux on a 64 bit Intel CPU (x86_64/amd64) running Linux.

Bus cross-compiling does not allow ‘cross-executing’: for doing so, you need to use an emulator such as qemu-arm, either explicitly, or by using binfmt-support as explained here.

If something is not clear in this answer, or if you think you are still missing a crucial piece of information, feel free to comment or augment your question accordingly.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement