$ gcc -S buffer-overflow.c && cat buffer-overflow.s
_foo:
pushl %ebp ;2
movl %esp, %ebp ;3
subl $16, %esp ;4
movl LC1, %eax ;5
movl %eax, -4(%ebp) ;6
leal -4(%ebp), %eax ;7
leal 8(%eax), %edx ;8
movl $_bad, %eax ;9
movl %eax, (%edx) ;10
开发者_JS百科 leave
ret
_main:
...
call _foo ;1
...
The help information says it should not compile nor assemble:
-S Compile only; do not assemble or link
Why are they contradictory?
A good explanation of the compiling
and linking
concepts is here.
Also, see this SO thread (difference between compiling and linking).
This is due to the difference of similarly-rooted "assembly" language (aka assembler) and "assembling" of the code (the process that "-S" help refers to).
assemble
means to translate the result of the compile
phase, and link
means to combine the results of the assemble phases of different executions of gcc together into an executable or library.
The compile
phase takes the result of the preprocessing phase and results in assembler code, roughly.
精彩评论