By definition , an object code is a set of instructions for a particular processor architecture. Take the GCC compiler. If you compile the same code from under different platforms (Linux / Windows etc.), but on the same hardware, the output will look like the same * .o files that will not be cross-platform. Why?

To eliminate the difference in library implementations, take the code without them, something like:

//main.c int main() { return 5+3; } //main.c EOF 
  • Take a walk through the objdump . You will see that each platform has its own cockroaches, necessary for the final assembly of the executable file. - PinkTux
  • You forget about initialization before starting the main ... - Vladimir Martyanov
  • Each platform has its own system calls, its own parameter transfer agreements, its own implementation of the standard library. And C ++ doesn’t have a binary standard . Now, if someone persuades system developers to unify everything, and the standardization committee to adopt a binary standard, agreeing with a possible one percent loss of efficiency (which is considered a sacred cow in the world of advantages), then we can talk about cross-platform object files. - VladD
  • @VladD, so, after all, object files are not a set of instructions of the processor and its firmware, but the code for the platform under which it was compiled? - Lurking Elk
  • @DimTeam: What's the difference? The code does not run in a vacuum on a clean processor. It calls other functions, maybe implicitly. He has a convention passing parameters. Everything is complicated :) - VladD

1 answer 1

By definition, an object code is a set of instructions for a particular processor architecture.

It's true. But NOT the whole truth. In addition to the actual instructions of the processor, it contains a table of external links, a table of roaming addresses, etc. These tables are used by the loader / linker when preparing the object module for execution.

Neither the tables themselves, nor the method of setting up the object module are standardized. Therefore, an object module prepared for execution on one platform cannot be executed on another.

One could try to write a not very complicated translator of one format into another, but the problem is practically insoluble, because not only the format of the object module itself is different, but also the format of calls to external functions (stack structure) and even the format of calling OS functions. Case dead ...