开发者

Can you explain why gcc -S output something like assemble?

开发者 https://www.devze.com 2022-12-24 04:58 出处:网络
$ gcc -S buffer-overflow.c && cat buffer-overflow.s _foo: pushl%ebp;2 movl%esp, %ebp;3 subl$16, %esp;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 
  开发者_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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号