tags:

views:

66

answers:

4
$ 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 
        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: 

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.

Johannes Schaub - litb
A: 

"assembling" means "compiling an assembly source code". -S just outputs the assembly code, does not assemble it.

ssg
+2  A: 

A good explanation of the compiling and linking concepts is here.

Also, see this SO thread (difference between compiling and linking).

Lazer
Mask
@Mask: from Wikipedia(http://en.wikipedia.org/wiki/Compiler): "A compiler is something that transforms source code written in a computer language (the source language) into another computer language." So compiling + assembling = compiling :)
Lazer
+1  A: 

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).

DVK