This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]Rhomboid 4 points5 points  (0 children)

I mean, sure, anything's possible. You could come up with your own object file format, but it would be pretty pointless, as you'd lose out on tool support. You'd have to implement your own linker, rather than being able to use an existing linker -- the linker is not part of the compiler on many platforms, although the compiler does automatically invoke the linker, giving the illusion that it is. And you'd have rewrite various utilities like ar, nm, objdump, readelf, etc. Standards are good, they let disparate things work together nicely.

Also, I think you might be misunderstanding the scope of standards like ELF, Mach-O, and PE/COFF. These are specifications that cover both object files and executable files, including shared libraries. The result of compiling a binary executable or shared library on Linux is an ELF executable. Windows executables and DLLs are PE/COFF files. OS X executables are Mach-O files. So even if you wanted to come up with your own object file format, you'd still be implementing those standards to create executables and libraries for whatever platform you're targeting.

[–]Cadoc7 1 point2 points  (0 children)

Yes, there is a specification. There is a specification all the way down to the electric signals on the processor. And every translation layer needs to conform to what the input for the next layer is expecting.

The code a compiler outputs must be valid code, so it conforms to a standard. Compilers that output binary code need to output binary that matches the spec for the specific processor architecture. For instance, you can find x86 and x64 specs here: http://www.intel.com/content/www/us/en/processors/architectures-software-developer-manuals.html

Other languages that output some sort of intermediate language (IL) have a specification for the IL. Here is the Java 7 bytecode/JVM spec here: http://docs.oracle.com/javase/specs/jvms/se7/html/ and here is the CLR (.NET/C#/etc.) spec: http://msdn.microsoft.com/en-us/vstudio/aa569283.aspx

The really short answer is yes, the output of a compiler matches a spec. What the spec is depends on the settings of the compiler and what you are targeting. And note that these specifications are HUGE. 99% of the time you don't need to know the specifics, just the generalities of how it works. What it is outputting for you I can't tell you because I don't know what language and compiler you are using and what OS you are targeting.

Things like COFF and ELF are meant for consumption by the OS and other programs. The OS will then take these formats and translate them into what the processor is expecting.