Created
July 19, 2010 00:24
-
-
Save bdonlan/480856 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// C++コード | |
struct Foo { | |
Foo(); | |
~Foo(); | |
}; | |
Foo *constructFoo() { | |
return new Foo(); | |
} | |
void destructFoo(Foo *foo) { | |
delete foo; | |
} | |
// asm出力 | |
.file "test.cpp" | |
.globl _Unwind_Resume | |
.text | |
.globl _Z12constructFoov | |
.type _Z12constructFoov, @function | |
//////// Foo *constructFoo() | |
_Z12constructFoov: | |
.LFB0: | |
.cfi_startproc | |
.cfi_personality 0x0,__gxx_personality_v0 | |
.cfi_lsda 0x0,.LLSDA0 | |
pushl %ebp | |
.cfi_def_cfa_offset 8 | |
movl %esp, %ebp | |
.cfi_offset 5, -8 | |
.cfi_def_cfa_register 5 | |
pushl %edi | |
pushl %esi | |
pushl %ebx | |
subl $28, %esp | |
//// Fooにメンバーがないので、サイズが1バイトになります。 | |
//// なので、ここで1の関数をスタックに置きます。 | |
movl $1, (%esp) | |
.LEHB0: | |
.cfi_offset 3, -20 | |
.cfi_offset 6, -16 | |
.cfi_offset 7, -12 | |
//// void *operator new(unsigned int)を呼びます | |
call _Znwj | |
.LEHE0: | |
//// 戻り値はeaxにあるので | |
movl %eax, %ebx | |
movl %ebx, %eax | |
//// これでまたスタックに置きます | |
movl %eax, (%esp) | |
.LEHB1: | |
//// コンストラクタのFoo::Foo()を呼びます | |
call _ZN3FooC1Ev | |
.LEHE1: | |
jmp .L6 | |
.L5: | |
.L3: | |
//// ここらへんはエクセプション対応のためのコードです。 | |
//// Foo::Foo()にエクセプションが起きてしまう場合はこれで | |
//// newからもらったメモリーを戻します | |
movl %edx, %esi | |
movl %eax, %edi | |
movl %ebx, (%esp) | |
//// operator delete(void*)を呼びます | |
call _ZdlPv | |
movl %edi, %eax | |
movl %esi, %edx | |
movl %eax, (%esp) | |
.LEHB2: | |
//// エクセプションを次のハンドラーに任せます | |
call _Unwind_Resume | |
.LEHE2: | |
.L6: | |
//// 普段のリターン作業 | |
movl %ebx, %eax | |
addl $28, %esp | |
popl %ebx | |
popl %esi | |
popl %edi | |
popl %ebp | |
ret | |
.cfi_endproc | |
.LFE0: | |
.size _Z12constructFoov, .-_Z12constructFoov | |
.globl __gxx_personality_v0 | |
.section .gcc_except_table,"a",@progbits | |
.LLSDA0: | |
.byte 0xff | |
.byte 0xff | |
.byte 0x1 | |
.uleb128 .LLSDACSE0-.LLSDACSB0 | |
.LLSDACSB0: | |
.uleb128 .LEHB0-.LFB0 | |
.uleb128 .LEHE0-.LEHB0 | |
.uleb128 0x0 | |
.uleb128 0x0 | |
.uleb128 .LEHB1-.LFB0 | |
.uleb128 .LEHE1-.LEHB1 | |
.uleb128 .L5-.LFB0 | |
.uleb128 0x0 | |
.uleb128 .LEHB2-.LFB0 | |
.uleb128 .LEHE2-.LEHB2 | |
.uleb128 0x0 | |
.uleb128 0x0 | |
.LLSDACSE0: | |
.text | |
.globl _Z11destructFooP3Foo | |
.type _Z11destructFooP3Foo, @function | |
_Z11destructFooP3Foo: | |
.LFB1: | |
.cfi_startproc | |
.cfi_personality 0x0,__gxx_personality_v0 | |
pushl %ebp | |
.cfi_def_cfa_offset 8 | |
movl %esp, %ebp | |
.cfi_offset 5, -8 | |
.cfi_def_cfa_register 5 | |
pushl %ebx | |
subl $20, %esp | |
//// まずはパラメータをレジスターに入れてから | |
movl 8(%ebp), %ebx | |
.cfi_offset 3, -12 | |
testl %ebx, %ebx | |
je .L9 | |
//// またスタックに置きます | |
movl %ebx, (%esp) | |
//// Foo::~Foo()を呼びます | |
call _ZN3FooD1Ev | |
movl %ebx, (%esp) | |
//// そしてoperator delete(void*)を呼びます | |
call _ZdlPv | |
.L9: | |
addl $20, %esp | |
popl %ebx | |
popl %ebp | |
ret | |
.cfi_endproc | |
.LFE1: | |
.size _Z11destructFooP3Foo, .-_Z11destructFooP3Foo | |
.ident "GCC: (Debian 4.4.4-6) 4.4.4" | |
.section .note.GNU-stack,"",@progbits |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment