This question already has answers here:
How to remove “noise” from GCC/clang assembly output?
(3个答案)
3年前关闭。
通过使用C编写语句,使用“ gcc -S”进行编译并研究输出,我一直在教自己GNU汇编。对于此代码(仅作为示例),这在x86(并使用-m32编译)上正常工作,但在我的AMD64盒中有效:
海湾合作委员会给我:
.file“ test.c”
。文本
.globl主
.type main,@功能
主要:
.LFB2:
pushq%rbp
.LCFI0:
movq%rsp,%rbp
.LCFI1:
movl $ 0,%eax
离开
退回
.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”
。文本
.globl主
.type main,@功能
主要:
第4张(%esp),%ecx
andl $ -16,%esp
pushl -4(%ecx)
Pushl%ebp
move%esp,%ebp
pushl%ecx
movl $ 0,%eax
popl%ecx
popl%ebp
leal -4(%ecx),%esp
退回
.size main,.- main
.ident“ GCC:(Ubuntu 4.3.3-5ubuntu4)4.3.3”
.section .note.GNU-stack,“”,@ progbits
在x86上。
有没有办法使x86_64输出程序集上的GCC -S没有起毛?
(3个答案)
3年前关闭。
通过使用C编写语句,使用“ gcc -S”进行编译并研究输出,我一直在教自己GNU汇编。对于此代码(仅作为示例),这在x86(并使用-m32编译)上正常工作,但在我的AMD64盒中有效:
int main()
{
return 0;
}
海湾合作委员会给我:
.file“ test.c”
。文本
.globl主
.type main,@功能
主要:
.LFB2:
pushq%rbp
.LCFI0:
movq%rsp,%rbp
.LCFI1:
movl $ 0,%eax
离开
退回
.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”
。文本
.globl主
.type main,@功能
主要:
第4张(%esp),%ecx
andl $ -16,%esp
pushl -4(%ecx)
Pushl%ebp
move%esp,%ebp
pushl%ecx
movl $ 0,%eax
popl%ecx
popl%ebp
leal -4(%ecx),%esp
退回
.size main,.- main
.ident“ GCC:(Ubuntu 4.3.3-5ubuntu4)4.3.3”
.section .note.GNU-stack,“”,@ progbits
在x86上。
有没有办法使x86_64输出程序集上的GCC -S没有起毛?
最佳答案
.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