在哪里可以找到GCC组件输出中调用的过程的汇编代码?

Vil*_*ray 1 c linux assembly gcc disassembly

我一直在玩GCC的汇编输出开关:

gcc -S -c helloworld.c
Run Code Online (Sandbox Code Playgroud)

helloworld.c:

#include <stdio.h>

int main(void){
    printf("Hello World!\n");
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

helloworld.s:

    .file   "helloworld.c"
    .section    .rodata
.LC0:
    .string "Hello World!"
    .text
    .globl  main
    .type   main, @function
main:
.LFB0:
    .cfi_startproc
    pushq   %rbp
    .cfi_def_cfa_offset 16
    .cfi_offset 6, -16
    movq    %rsp, %rbp
    .cfi_def_cfa_register 6
    movl    $.LC0, %edi
    call    puts
    movl    $0, %eax
    popq    %rbp
    .cfi_def_cfa 7, 8
    ret
    .cfi_endproc
.LFE0:
    .size   main, .-main
    .ident  "GCC: (Debian 4.7.2-5) 4.7.2"
    .section    .note.GNU-stack,"",@progbits
Run Code Online (Sandbox Code Playgroud)

在输出helloworld.s文件中,我注意到汇编命令输出"Hello World!" 文字很简单:

call puts
Run Code Online (Sandbox Code Playgroud)

但是,该helloworld.s1文件中没有puts过程汇编代码.我在哪里可以查看此汇编代码?

Igo*_*sky 7

编辑:这实际上不是原始问题的答案,但由于它正在上升,信息似乎是有用的,所以......


这是GCC的优化.由于您的字符串不包含任何格式字符并以换行结束,因此GCC会替换puts产生相同输出但速度更快的调用(因为它不需要扫描字符串以获取格式说明符).尝试类似的东西:

int main(int argc, char *argv[]){
    printf("Hello World!\nargc=%d", argc);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

你会printf在集会中看到你的.

  • 问题似乎是"put`的汇编源码在哪里?"而不是"为什么用`puts`代替`printf`?" (2认同)