Created
September 2, 2012 15:10
-
-
Save YukiSakamoto/3600272 to your computer and use it in GitHub Desktop.
gcc extension-sample(constructor & destructor)
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
#include <stdio.h> | |
__attribute__((constructor)) | |
int pre_main(void) | |
{ | |
printf("%s\n", __func__); | |
getchar(); | |
return 0; | |
} | |
__attribute__((destructor)) | |
int after_main(void) | |
{ | |
printf("%s\n", __func__); | |
return 0; | |
} | |
int main(void) | |
{ | |
printf("%s\n", __func__); | |
return 0; | |
} |
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
.section __TEXT,__text,regular,pure_instructions | |
.globl _pre_main | |
.align 4, 0x90 | |
_pre_main: | |
pushl %ebp | |
movl %esp, %ebp | |
subl $24, %esp | |
call L1$pb | |
L1$pb: | |
popl %eax | |
leal ___func__.1863-L1$pb(%eax), %eax | |
movl %eax, (%esp) | |
call _puts | |
call _getchar | |
movl $0, -8(%ebp) | |
movl -8(%ebp), %eax | |
movl %eax, -4(%ebp) | |
movl -4(%ebp), %eax | |
addl $24, %esp | |
popl %ebp | |
ret | |
.globl _after_main | |
.align 4, 0x90 | |
_after_main: | |
pushl %ebp | |
movl %esp, %ebp | |
subl $24, %esp | |
call L2$pb | |
L2$pb: | |
popl %eax | |
leal ___func__.1869-L2$pb(%eax), %eax | |
movl %eax, (%esp) | |
call _puts | |
movl $0, -8(%ebp) | |
movl -8(%ebp), %eax | |
movl %eax, -4(%ebp) | |
movl -4(%ebp), %eax | |
addl $24, %esp | |
popl %ebp | |
ret | |
.globl _main | |
.align 4, 0x90 | |
_main: | |
pushl %ebp | |
movl %esp, %ebp | |
subl $24, %esp | |
call L3$pb | |
L3$pb: | |
popl %eax | |
leal ___func__.1875-L3$pb(%eax), %eax | |
movl %eax, (%esp) | |
call _puts | |
movl $0, -8(%ebp) | |
movl -8(%ebp), %eax | |
movl %eax, -4(%ebp) | |
movl -4(%ebp), %eax | |
addl $24, %esp | |
popl %ebp | |
ret | |
.section __TEXT,__cstring,cstring_literals | |
.align 2 | |
___func__.1863: | |
.asciz "pre_main" | |
.align 2 | |
___func__.1869: | |
.asciz "after_main" | |
.align 2 | |
___func__.1875: | |
.asciz "main" | |
.section __DATA,__mod_init_func,mod_init_funcs | |
.align 2 | |
.long _pre_main | |
.section __DATA,__mod_term_func,mod_term_funcs | |
.align 2 | |
.long _after_main | |
.subsections_via_symbols |
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
construct: ファイル形式 mach-o-i386 | |
セクション .text の逆アセンブル: | |
00001e70 <start>: | |
1e70: 6a 00 push $0x0 | |
1e72: 89 e5 mov %esp,%ebp | |
1e74: 83 e4 f0 and $0xfffffff0,%esp | |
1e77: 83 ec 10 sub $0x10,%esp | |
1e7a: 8b 5d 04 mov 0x4(%ebp),%ebx | |
1e7d: 89 1c 24 mov %ebx,(%esp) | |
1e80: 8d 4d 08 lea 0x8(%ebp),%ecx | |
1e83: 89 4c 24 04 mov %ecx,0x4(%esp) | |
1e87: 83 c3 01 add $0x1,%ebx | |
1e8a: c1 e3 02 shl $0x2,%ebx | |
1e8d: 01 cb add %ecx,%ebx | |
1e8f: 89 5c 24 08 mov %ebx,0x8(%esp) | |
1e93: 8b 03 mov (%ebx),%eax | |
1e95: 83 c3 04 add $0x4,%ebx | |
1e98: 85 c0 test %eax,%eax | |
1e9a: 75 f7 jne 1e93 <start+0x23> | |
1e9c: 89 5c 24 0c mov %ebx,0xc(%esp) | |
1ea0: e8 7b 00 00 00 call 1f20 <_main> | |
1ea5: 89 04 24 mov %eax,(%esp) | |
1ea8: e8 a3 00 00 00 call 1f50 <_exit$stub> | |
1ead: f4 hlt | |
1eae: 90 nop | |
1eaf: 90 nop | |
00001eb0 <_pre_main>: | |
1eb0: 55 push %ebp | |
1eb1: 89 e5 mov %esp,%ebp | |
1eb3: 83 ec 18 sub $0x18,%esp | |
1eb6: e8 00 00 00 00 call 1ebb <_pre_main+0xb> | |
1ebb: 58 pop %eax | |
1ebc: 8d 80 d5 00 00 00 lea 0xd5(%eax),%eax | |
1ec2: 89 04 24 mov %eax,(%esp) | |
1ec5: e8 92 00 00 00 call 1f5c <_puts$stub> | |
1eca: e8 87 00 00 00 call 1f56 <_getchar$stub> | |
1ecf: c7 45 f8 00 00 00 00 movl $0x0,-0x8(%ebp) | |
1ed6: 8b 45 f8 mov -0x8(%ebp),%eax | |
1ed9: 89 45 fc mov %eax,-0x4(%ebp) | |
1edc: 8b 45 fc mov -0x4(%ebp),%eax | |
1edf: 83 c4 18 add $0x18,%esp | |
1ee2: 5d pop %ebp | |
1ee3: c3 ret | |
1ee4: 66 0f 1f 44 00 00 nopw 0x0(%eax,%eax,1) | |
1eea: 66 0f 1f 44 00 00 nopw 0x0(%eax,%eax,1) | |
00001ef0 <_after_main>: | |
1ef0: 55 push %ebp | |
1ef1: 89 e5 mov %esp,%ebp | |
1ef3: 83 ec 18 sub $0x18,%esp | |
1ef6: e8 00 00 00 00 call 1efb <_after_main+0xb> | |
1efb: 58 pop %eax | |
1efc: 8d 80 a1 00 00 00 lea 0xa1(%eax),%eax | |
1f02: 89 04 24 mov %eax,(%esp) | |
1f05: e8 52 00 00 00 call 1f5c <_puts$stub> | |
1f0a: c7 45 f8 00 00 00 00 movl $0x0,-0x8(%ebp) | |
1f11: 8b 45 f8 mov -0x8(%ebp),%eax | |
1f14: 89 45 fc mov %eax,-0x4(%ebp) | |
1f17: 8b 45 fc mov -0x4(%ebp),%eax | |
1f1a: 83 c4 18 add $0x18,%esp | |
1f1d: 5d pop %ebp | |
1f1e: c3 ret | |
1f1f: 90 nop | |
00001f20 <_main>: | |
1f20: 55 push %ebp | |
1f21: 89 e5 mov %esp,%ebp | |
1f23: 83 ec 18 sub $0x18,%esp | |
1f26: e8 00 00 00 00 call 1f2b <_main+0xb> | |
1f2b: 58 pop %eax | |
1f2c: 8d 80 7d 00 00 00 lea 0x7d(%eax),%eax | |
1f32: 89 04 24 mov %eax,(%esp) | |
1f35: e8 22 00 00 00 call 1f5c <_puts$stub> | |
1f3a: c7 45 f8 00 00 00 00 movl $0x0,-0x8(%ebp) | |
1f41: 8b 45 f8 mov -0x8(%ebp),%eax | |
1f44: 89 45 fc mov %eax,-0x4(%ebp) | |
1f47: 8b 45 fc mov -0x4(%ebp),%eax | |
1f4a: 83 c4 18 add $0x18,%esp | |
1f4d: 5d pop %ebp | |
1f4e: c3 ret | |
セクション __TEXT.__symbol_stub の逆アセンブル: | |
00001f50 <_exit$stub>: | |
1f50: ff 25 1c 20 00 00 jmp *0x201c | |
00001f56 <_getchar$stub>: | |
1f56: ff 25 20 20 00 00 jmp *0x2020 | |
00001f5c <_puts$stub>: | |
1f5c: ff 25 24 20 00 00 jmp *0x2024 | |
セクション __TEXT.__stub_helper の逆アセンブル: | |
00001f64 <__TEXT.__stub_helper>: | |
1f64: 68 00 00 00 00 push $0x0 | |
1f69: e9 16 00 00 00 jmp 1f84 <_puts$stub+0x28> | |
1f6e: 68 0c 00 00 00 push $0xc | |
1f73: e9 0c 00 00 00 jmp 1f84 <_puts$stub+0x28> | |
1f78: 68 1b 00 00 00 push $0x1b | |
1f7d: e9 02 00 00 00 jmp 1f84 <_puts$stub+0x28> | |
1f82: 00 00 add %al,(%eax) | |
1f84: 68 18 20 00 00 push $0x2018 | |
1f89: ff 25 14 20 00 00 jmp *0x2014 | |
1f8f: 90 nop | |
セクション __TEXT.__unwind_info の逆アセンブル: | |
00001fad <__TEXT.__unwind_info>: | |
1fad: 01 00 add %eax,(%eax) | |
1faf: 00 00 add %al,(%eax) | |
1fb1: 1c 00 sbb $0x0,%al | |
1fb3: 00 00 add %al,(%eax) | |
1fb5: 00 00 add %al,(%eax) | |
1fb7: 00 00 add %al,(%eax) | |
1fb9: 1c 00 sbb $0x0,%al | |
1fbb: 00 00 add %al,(%eax) | |
1fbd: 00 00 add %al,(%eax) | |
1fbf: 00 00 add %al,(%eax) | |
1fc1: 1c 00 sbb $0x0,%al | |
1fc3: 00 00 add %al,(%eax) | |
1fc5: 02 00 add (%eax),%al | |
1fc7: 00 00 add %al,(%eax) | |
1fc9: 70 0e jo 1fd9 <___func__.1875+0x31> | |
1fcb: 00 00 add %al,(%eax) | |
1fcd: 34 00 xor $0x0,%al | |
1fcf: 00 00 add %al,(%eax) | |
1fd1: 34 00 xor $0x0,%al | |
1fd3: 00 00 add %al,(%eax) | |
1fd5: 50 push %eax | |
1fd6: 0f 00 00 sldt (%eax) | |
1fd9: 00 00 add %al,(%eax) | |
1fdb: 00 00 add %al,(%eax) | |
1fdd: 34 00 xor $0x0,%al | |
1fdf: 00 00 add %al,(%eax) | |
1fe1: 03 00 add (%eax),%eax | |
1fe3: 00 00 add %al,(%eax) | |
1fe5: 0c 00 or $0x0,%al | |
1fe7: 01 00 add %eax,(%eax) | |
1fe9: 10 00 adc %al,(%eax) | |
1feb: 01 00 add %eax,(%eax) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment