Assembly versus binary output

Is it better for the compiler to compile code in assembly language or directly output binary machine code?

The advantages of the assembly language that I can think up from head to toe: avoid the need to learn the format of the object file, ease of debugging the backend.

The advantage of binary: speed up compilation speed. How important is it? Assuming Gnu assembler is being used (among other things, this can be reasonably assumed to be available on most machines), does it take a significant amount of time to collect, say, a million lines of code?

Are there any differences in object file formats between the various operating systems that the assembler has hidden?

Are there any other advantages on both sides that I have not thought about?

+3
source share
6 answers

The assembly is easier to output, and it has the advantage of being human readable. Regarding compilation time, here are some statistics from my compiler:

[~/ecc/ellcc/ecc/Main] main% ../../bin/x86-elf-ecc test/sieve.c -time-actions
===-------------------------------------------------------------------------===
                   ... Ellcc action timing report ...
===-------------------------------------------------------------------------===
Total Execution Time: 2.9006 seconds (2.9857 wall clock)

---User Time---   --System Time--   --User+System--   ---Wall Time---  --- Name ---
2.0397 ( 71.3%)   0.0250 ( 65.8%)   2.0647 ( 71.2%)   2.1174 ( 70.9%)  Bitcode linking
0.7999 ( 27.9%)   0.0070 ( 18.4%)   0.8069 ( 27.8%)   0.8111 ( 27.2%)  Generating
0.0000 (  0.0%)   0.0010 (  2.6%)   0.0010 (  0.0%)   0.0274 (  0.9%)  Assembly
0.0110 (  0.4%)   0.0030 (  7.9%)   0.0140 (  0.5%)   0.0143 (  0.5%)  LLVM generation
0.0070 (  0.2%)   0.0000 (  0.0%)   0.0070 (  0.2%)   0.0066 (  0.2%)  Type checking
0.0000 (  0.0%)   0.0020 (  5.3%)   0.0020 (  0.1%)   0.0041 (  0.1%)  Linking
0.0030 (  0.1%)   0.0000 (  0.0%)   0.0030 (  0.1%)   0.0031 (  0.1%)  Optimization
0.0010 (  0.0%)   0.0000 (  0.0%)   0.0010 (  0.0%)   0.0010 (  0.0%)  Elaboration
0.0010 (  0.0%)   0.0000 (  0.0%)   0.0010 (  0.0%)   0.0004 (  0.0%)  Integrity checking
0.0000 (  0.0%)   0.0000 (  0.0%)   0.0000 (  0.0%)   0.0004 (  0.0%)  Parsing
2.8626 (100.0%)   0.0380 (100.0%)   2.9006 (100.0%)   2.9857 (100.0%)  TOTAL

[~/ecc/ellcc/ecc/Main] main%

As you can see, build time is overshadowed by building and generating code. This example compiles and bundles together a small main () together with the standard library, all in an intermediate LLVM form. Then a single assembly language file is created for the entire program. This file is linked (actually moved) using the linker that creates the a.out file.

+3
source

: , , , .

+2

,

  • , ;
  • , .. .

, / . ? , 5 . , , 100 1000 . .

, .

+2

, , I-, . , , . 20 Standard ML of New Jersey.

+1

, ?

, . (, MASM , , OMF COFF, .)

More information about the various formats of object files can be found in the corresponding section in this document .

+1
source

you can try how long it takes to build the assembly for your code:

gcc -O2 -S -c foo.c
0
source

Source: https://habr.com/ru/post/1727232/


All Articles