Are binaries portable across different CPU architectures?

foob

My goal is to be able to develop for embedded Linux. I have experience on bare-metal embedded systems using ARM.

I have some general questions about developing for different cpu targets. My questions are as below:

  1. If I have an application compiled to run on a 'x86 target, linux OS version x.y.z', can I just run the same compiled binary on another system 'ARM target, linux OS version x.y.z'?

  2. If above is not true, the only way is to get the application source code to rebuild/recompile using the relevant toolchain 'for example, arm-linux-gnueabi'?

  3. Similarly, if I have a loadable kernel module (device driver) that works on a 'x86 target, linux OS version x.y.z', can I just load/use the same compiled .ko on another system 'ARM target, linux OS version x.y.z'?

  4. If above is not true, the only way is to get the driver source code to rebuild/recompile using the relevant toolchain 'for example, arm-linux-gnueabi'?

Elizafox

No. Binaries must be (re)compiled for the target architecture, and Linux offers nothing like fat binaries out of the box. The reason is because the code is compiled to machine code for a specific architecture, and machine code is very different between most processor families (ARM and x86 for instance are very different).

EDIT: it is worth noting that some architectures offer levels of backwards compatibility (and even rarer, compatibility with other architectures); on 64-bit CPU's, it's common to have backwards compatibility to 32-bit editions (but remember: your dependent libraries must also be 32-bit, including your C standard library, unless you statically link). Also worth mentioning is Itanium, where it was possible to run x86 code (32-bit only), albeit very slowly; the poor execution speed of x86 code was at least part of the reason it wasn't very successful in the market.

Bear in mind that you still cannot use binaries compiled with newer instructions on older CPU's, even in compatibility modes (for example, you cannot use AVX in a 32-bit binary on Nehalem x86 processors; the CPU just doesn't support it.

Note that kernel modules must be compiled for the relevant architecture; in addition, 32-bit kernel modules will not work on 64-bit kernels or vice versa.

For information on cross-compiling binaries (so you don't have to have a toolchain on the target ARM device), see grochmal's comprehensive answer below.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why are linux system calls different across architectures

From

How Go compiled file works on different OS or CPU architectures?

From

Are Golang binaries portable?

From Dev

Portable binaries and the libexec path

From Dev

Portable binaries with Rust

From Dev

Referencing C Dlls from Windows 10 Universal App Across CPU Architectures

From Dev

Android APIs and CPU Architectures

From Dev

Portable MongoDB and MySQL/PostgreSQL binaries

From Dev

APT version conflicts across different architectures even with Multi-Arch: same?

From Dev

Google Play Store : How to upload more APKs to support different CPU architectures

From Dev

Programming on different ARM architectures

From Java

making proprietary ELF binaries portable on Linux

From Dev

Compile source as portable across directories

From Dev

Why is pointer arithmetic inconsistent across architectures?

From Java

Generate APK for different architectures - FFmpegMediaMetadataRetriever

From Dev

File operations in C on different architectures

From Dev

Behavior of getCString and withCString on different architectures

From Dev

Casting pointer types on different architectures

From Dev

openCV 3 remove unnecessary cpu architectures for Android

From Dev

Do any CPU architectures use Metadata?

From Dev

Android mobile chip architectures different in different countries?

From Dev

Is snap portable across other UNIX (example macOS)?

From Dev

`test` and `[` - different binaries, any difference?

From Dev

Is conversion from float to int consistent across all platforms and processor architectures?

From Dev

integration of libraries in the project under different architectures

From Dev

Android gradle, native libs for different architectures

From

Build dynamic targets for different architectures using make?

From Dev

How to Build Visual Studio Projects for Different Architectures

From Dev

Is Assembly Language syntax the same for different architectures

Related Related

  1. 1

    Why are linux system calls different across architectures

  2. 2

    How Go compiled file works on different OS or CPU architectures?

  3. 3

    Are Golang binaries portable?

  4. 4

    Portable binaries and the libexec path

  5. 5

    Portable binaries with Rust

  6. 6

    Referencing C Dlls from Windows 10 Universal App Across CPU Architectures

  7. 7

    Android APIs and CPU Architectures

  8. 8

    Portable MongoDB and MySQL/PostgreSQL binaries

  9. 9

    APT version conflicts across different architectures even with Multi-Arch: same?

  10. 10

    Google Play Store : How to upload more APKs to support different CPU architectures

  11. 11

    Programming on different ARM architectures

  12. 12

    making proprietary ELF binaries portable on Linux

  13. 13

    Compile source as portable across directories

  14. 14

    Why is pointer arithmetic inconsistent across architectures?

  15. 15

    Generate APK for different architectures - FFmpegMediaMetadataRetriever

  16. 16

    File operations in C on different architectures

  17. 17

    Behavior of getCString and withCString on different architectures

  18. 18

    Casting pointer types on different architectures

  19. 19

    openCV 3 remove unnecessary cpu architectures for Android

  20. 20

    Do any CPU architectures use Metadata?

  21. 21

    Android mobile chip architectures different in different countries?

  22. 22

    Is snap portable across other UNIX (example macOS)?

  23. 23

    `test` and `[` - different binaries, any difference?

  24. 24

    Is conversion from float to int consistent across all platforms and processor architectures?

  25. 25

    integration of libraries in the project under different architectures

  26. 26

    Android gradle, native libs for different architectures

  27. 27

    Build dynamic targets for different architectures using make?

  28. 28

    How to Build Visual Studio Projects for Different Architectures

  29. 29

    Is Assembly Language syntax the same for different architectures

HotTag

Archive