Usage differences between. a.out, .ELF, .EXE, and .COFF

前端 未结 1 882
情话喂你
情话喂你 2021-02-02 11:56

Don\'t get me wrong by looking at the question title - I know what they are (format for portable executable files). But my interest scope is slightly different

M

相关标签:
1条回答
  • 2021-02-02 12:18

    I am primarily a Windows user and know that when you compile your C/C++ code, you get something similar to .o or .obj. that are not executable

    Well, last time I compiled stuff on Windows, the result of the compilation was an .obj file, which is exactly what its name suggests: it's an object file. You're right in that it's not an executable in itself. It contains machine code which doesn't (yet) contain enough information to be directly run on the CPU.

    However, in Linux (or UNIX-like systems) there are .o files after you compile the C/C++ code. And once the linking is done, the executable is in a.out format (at least in Ubuntu distribution of Linux). It may very well be .elf in some other distrib.

    Living in the 90's, that is :P No modern compilers I am aware of target the a.out format as their default output format for object code. Maybe it's a misleading default of GCC to put the object code into a file called a.out when no explicit output file name is specified, but if you run the file command on a.out, you'll find out that it's an ELF file. The a.out format is ancient and it's kind of "de facto obsolete".

    What is the true definitions for portable executables and object code?

    You've already got the Wikipedia link to object files, here's the one to "Portable Executable".

    How is it that Windows and UNIX platform covers both executables annd object code under the same file format (.COFF, .elf).

    Because the ELF format (and apparently COFF too) has been designed like so. And why not? It's just the very same machine code after all, it seems quite logical to use one file format during all the compilation steps. Just like we don't like when dynamic libraries and stand-alone executables have a different format. (That's why ELF is called ELF - it's an "Executable and Linkable Format".)

    Am I misinterpreting "Linkable"?

    I don't know. From your question it's not clear to me what you think "linkable" is. In general, it means that it's a file that can be linked against, i. e. a library.

    Based on question 1. (and perhaps 2) do I need to use symbol tables (e.g. .LUM or .MAP files) with object code then? Symbols as in debug symbols and using them when re-hosting the object files on a different machine.

    I think this one is not related to the executable format used. If you want to debug, you have to generate debugging information no matter what. But if you don't need to debug, then you're free to omit them of course.

    0 讨论(0)
提交回复
热议问题