用gcc清理x86_64组件输出?

Joh*_*ohn 14 assembly gcc x86-64

我已经通过在C中编写语句,用"gcc -S"编译它们并研究输出,一直在教自己GNU Assembly一段时间.这在x86(并使用-m32编译)上工作正常,但在我的AMD64框中,对于此代码(仅作为示例):

int main()
{
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

GCC给了我:

 .file "test.c"
 .text
.globl main
 .type main, @function
main:
.LFB2:
 pushq %rbp
.LCFI0:
 movq %rsp, %rbp
.LCFI1:
 movl $0, %eax
 leave
 ret
.LFE2:
 .size main, .-main
 .section .eh_frame,"a",@progbits
.Lframe1:
 .long .LECIE1-.LSCIE1
.LSCIE1:
 .long 0x0
 .byte 0x1
 .string "zR"
 .uleb128 0x1
 .sleb128 -8
 .byte 0x10
 .uleb128 0x1
 .byte 0x3
 .byte 0xc
 .uleb128 0x7
 .uleb128 0x8
 .byte 0x90
 .uleb128 0x1
 .align 8
.LECIE1:
.LSFDE1:
 .long .LEFDE1-.LASFDE1
.LASFDE1:
 .long .LASFDE1-.Lframe1
 .long .LFB2
 .long .LFE2-.LFB2
 .uleb128 0x0
 .byte 0x4
 .long .LCFI0-.LFB2
 .byte 0xe
 .uleb128 0x10
 .byte 0x86
 .uleb128 0x2
 .byte 0x4
 .long .LCFI1-.LCFI0
 .byte 0xd
 .uleb128 0x6
 .align 8
.LEFDE1:
 .ident "GCC: (Ubuntu 4.3.3-5ubuntu4) 4.3.3"
 .section .note.GNU-stack,"",@progbits

和....相比:

 .file "test.c"
 .text
.globl main
 .type main, @function
main:
 leal 4(%esp), %ecx
 andl $-16, %esp
 pushl -4(%ecx)
 pushl %ebp
 movl %esp, %ebp
 pushl %ecx
 movl $0, %eax
 popl %ecx
 popl %ebp
 leal -4(%ecx), %esp
 ret
 .size main, .-main
 .ident "GCC: (Ubuntu 4.3.3-5ubuntu4) 4.3.3"
 .section .note.GNU-stack,"",@progbits

在x86上.

有没有办法在没有绒毛的x86_64输出组件上制作GCC -S?

sla*_*ais 5

您可以尝试将要学习的代码放在函数中.

例如:

int ftest(void)
{
    return 0;
}

int main(void)
{
    return ftest();
}
Run Code Online (Sandbox Code Playgroud)

如果您查看用于测试的组件源,它将尽可能干净.

..snip..
test:
.LFB2:
        pushq   %rbp
.LCFI0:
        movq    %rsp, %rbp
.LCFI1:
        movl    $0, %eax
        leave
        ret
..snip..
Run Code Online (Sandbox Code Playgroud)


Emp*_*ian 5

进入.eh_frame部分的内容是展开描述符,您只需要展开堆栈(例如使用GDB).在学习装配时,你可以简单地忽略它.这是一种做你想要的"清理"的方法:

gcc -S -o - test.c | sed -e '/^\.L/d' -e '/\.eh_frame/Q'
        .file   "test.c"
        .text
.globl main
        .type   main,@function
main:
        pushq   %rbp
        movq    %rsp, %rbp
        movl    $0, %eax
        leave
        ret
        .size   main,.Lfe1-main
Run Code Online (Sandbox Code Playgroud)

  • 删除所有`.L`本地标签对于带有循环或分支的函数来说不是很好:/ (2认同)