〔リスト1〕加算,減算,乗算に対する符号付きのオーバフローに対するトラップを生成する例(test189.c)
|
/*
*加算,減算,乗算に対する符号付きのオーバフローに対するトラップを生成
*/
#include <stdio.h>
int main()
{
int data1;
int data2;
int res;
data1 = 10;
data2 = 10;
res = data1 + data2;
printf("%d\n",res);
res = data1 - data2;
printf("%d\n",res);
//実際にオーバフローさせる処理
data1 = 1000000;
data2 = 8000000;
res = data1 * data2;
printf("%d\n",res);
return 0;
}
|
|
〔リスト2〕オプションなしで生成されたアセンブラソース(test189.s)
|
.file "test189.c"
.section .rodata
.LC0:
.string "%d\n"
.text
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
subl $24, %esp
andl $-16, %esp
movl $0, %eax
subl %eax, %esp
movl $10, -4(%ebp)
movl $10, -8(%ebp)
movl -8(%ebp), %eax
addl -4(%ebp), %eax
movl %eax, -12(%ebp)
movl -12(%ebp), %eax
movl %eax, 4(%esp)
movl $.LC0, (%esp)
call printf
movl -8(%ebp), %edx
movl -4(%ebp), %eax
subl %edx, %eax
movl %eax, -12(%ebp)
movl -12(%ebp), %eax
movl %eax, 4(%esp)
movl $.LC0, (%esp)
call printf
movl $1000000, -4(%ebp)
movl $8000000, -8(%ebp)
movl -4(%ebp), %eax
imull -8(%ebp), %eax
movl %eax, -12(%ebp)
movl -12(%ebp), %eax
movl %eax, 4(%esp)
movl $.LC0, (%esp)
call printf
movl $0, %eax
leave
ret
.size main, .-main
.ident "GCC: (GNU) 3.3"
|
|
〔リスト3〕オプション付きで生成されたアセンブラソース(test189a.s)
|
.file "test189.c"
.globl __addvsi3
.globl __subvsi3
.globl __mulvsi3
.section .rodata
.LC0:
.string "%d\n"
.text
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
subl $40, %esp
andl $-16, %esp
movl $0, %eax
subl %eax, %esp
movl $10, -4(%ebp)
movl $10, -8(%ebp)
movl -8(%ebp), %eax
movl %eax, 4(%esp)
movl -4(%ebp), %eax
movl %eax, (%esp)
call __addvsi3
movl %eax, -12(%ebp)
movl -12(%ebp), %eax
movl %eax, 4(%esp)
movl $.LC0, (%esp)
call printf
movl -8(%ebp), %eax
movl %eax, 4(%esp)
movl -4(%ebp), %eax
movl %eax, (%esp)
call __subvsi3
movl %eax, -12(%ebp)
movl -12(%ebp), %eax
movl %eax, 4(%esp)
movl $.LC0, (%esp)
call printf
movl $1000000, -4(%ebp)
movl $8000000, -8(%ebp)
movl -8(%ebp), %eax
movl %eax, 4(%esp)
movl -4(%ebp), %eax
movl %eax, (%esp)
call __mulvsi3
movl %eax, -12(%ebp)
movl -12(%ebp), %eax
movl %eax, 4(%esp)
movl $.LC0, (%esp)
call printf
movl $0, %eax
leave
ret
.size main, .-main
.ident "GCC: (GNU) 3.3"
|
|
〔リスト4〕test189.cから生成されたアセンブラソース(test189b.s)
|
.file "test190.c"
.section .rodata
.LC0:
.string "%d\n"
.text
.globl main
.type main, @function
main:
.LFB3:
pushl %ebp
.LCFI0:
movl %esp, %ebp
.LCFI1:
subl $24, %esp
.LCFI2:
andl $-16, %esp
movl $0, %eax
subl %eax, %esp
movl $10, -4(%ebp)
movl $10, -8(%ebp)
movl -8(%ebp), %eax
addl -4(%ebp), %eax
movl %eax, -12(%ebp)
movl -12(%ebp), %eax
movl %eax, 4(%esp)
movl $.LC0, (%esp)
call printf
movl -8(%ebp), %edx
movl -4(%ebp), %eax
subl %edx, %eax
movl %eax, -12(%ebp)
movl -12(%ebp), %eax
movl %eax, 4(%esp)
movl $.LC0, (%esp)
call printf
movl $1000000, -4(%ebp)
movl $8000000, -8(%ebp)
movl -4(%ebp), %eax
imull -8(%ebp), %eax
movl %eax, -12(%ebp)
movl -12(%ebp), %eax
movl %eax, 4(%esp)
movl $.LC0, (%esp)
call printf
movl $0, %eax
leave
ret
.LFE3:
.size main, .-main
.section .eh_frame,"a",@progbits
.Lframe1:
.long .LECIE1-.LSCIE1
.LSCIE1:
.long 0x0
.byte 0x1
.string ""
.uleb128 0x1
.sleb128 -4
.byte 0x8
.byte 0xc
.uleb128 0x4
.uleb128 0x4
.byte 0x88
.uleb128 0x1
.align 4
.LECIE1:
.LSFDE1:
.long .LEFDE1-.LASFDE1
.LASFDE1:
.long .LASFDE1-.Lframe1
.long .LFB3
.long .LFE3-.LFB3
.byte 0x4
.long .LCFI0-.LFB3
.byte 0xe
.uleb128 0x8
.byte 0x85
.uleb128 0x2
.byte 0x4
.long .LCFI1-.LCFI0
.byte 0xd
.uleb128 0x5
.align 4
.LEFDE1:
.ident "GCC: (GNU) 3.3"
|
|
〔リスト5〕test189.cから生成されたアセンブラソース(test191.s)
|
.file "test191.c"
.section .rodata
.LC0:
.string "%d\n"
.text
.globl main
.type main, @function
main:
.LFB3:
pushl %ebp
.LCFI0:
movl %esp, %ebp
.LCFI1:
subl $24, %esp
.LCFI2:
andl $-16, %esp
movl $0, %eax
subl %eax, %esp
movl $10, -4(%ebp)
movl $10, -8(%ebp)
movl -8(%ebp), %eax
addl -4(%ebp), %eax
movl %eax, -12(%ebp)
movl -12(%ebp), %eax
movl %eax, 4(%esp)
movl $.LC0, (%esp)
call printf
movl $0, %eax
leave
ret
.LFE3:
.size main, .-main
.section .eh_frame,"a",@progbits
.Lframe1:
.long .LECIE1-.LSCIE1
.LSCIE1:
.long 0x0
.byte 0x1
.string ""
.uleb128 0x1
.sleb128 -4
.byte 0x8
.byte 0xc
.uleb128 0x4
.uleb128 0x4
.byte 0x88
.uleb128 0x1
.align 4
.LECIE1:
.LSFDE1:
.long .LEFDE1-.LASFDE1
.LASFDE1:
.long .LASFDE1-.Lframe1
.long .LFB3
.long .LFE3-.LFB3
.byte 0x4
.long .LCFI0-.LFB3
.byte 0xe
.uleb128 0x8
.byte 0x85
.uleb128 0x2
.byte 0x4
.long .LCFI1-.LCFI0
.byte 0xd
.uleb128 0x5
.align 4
.LEFDE1:
.ident "GCC: (GNU) 3.3"
|
|
〔リスト6〕wchar_tのサイズをオプションで変更する例(test192.c)
|
/*
*wchar_tのサイズ
*/
#include <stdio.h>
int main()
{
printf("%d\n",sizeof(wchar_t));
return 0;
}
|
|
〔リスト7〕オプションなしで生成されたアセンブラソース(test192.s)
|
.file "test192.c"
.section .rodata
.LC0:
.string "%d\n"
.text
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
andl $-16, %esp
movl $0, %eax
subl %eax, %esp
movl $4, 4(%esp)
movl $.LC0, (%esp)
call printf
movl $0, %eax
leave
ret
.size main, .-main
.ident "GCC: (GNU) 3.3"
|
|
〔リスト8〕オプション付きで生成されたアセンブラソース
|
(test192a.s)
.file "test192.c"
.section .rodata
.LC0:
.string "%d\n"
.text
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
andl $-16, %esp
movl $0, %eax
subl %eax, %esp
movl $2, 4(%esp)
movl $.LC0, (%esp)
call printf
movl $0, %eax
leave
ret
.size main, .-main
.ident "GCC: (GNU) 3.3"
|
|
〔リスト9〕スタックの制限をオプションで変更する例(test193.c)
|
/*
*スタックの制限をオプションで変更する例
*/
#include <stdio.h>
int main()
{
int tbl[5];
int ix;
for(ix=0;ix<20;ix++)
{
tbl[ix] = ix;
printf("%d\n",ix);
}
return 0;
}
|
|
〔リスト10〕オプション付きで生成されたアセンブラソース(test193a.s)
|
.file "test193.c"
.section .rodata
.LC0:
.string "%d\n"
.text
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
subl $72, %esp
andl $-16, %esp
movl $0, -48(%ebp)
movl %esp, %eax
subl %ecx, %eax
cmpl -48(%ebp), %eax
jae .L2
int $5
.L2:
subl -48(%ebp), %esp
movl $0, -44(%ebp)
.L3:
cmpl $19, -44(%ebp)
jle .L6
jmp .L4
.L6:
movl -44(%ebp), %edx
movl -44(%ebp), %eax
movl %eax, -40(%ebp,%edx,4)
movl -44(%ebp), %eax
movl %eax, 4(%esp)
movl $.LC0, (%esp)
call printf
leal -44(%ebp), %eax
incl (%eax)
jmp .L3
.L4:
movl $0, %eax
leave
ret
.size main, .-main
.ident "GCC: (GNU) 3.3"
|
|
〔リスト11〕-finstrument-functionsを指定する例(test194.c)
|
/*
*-finstrument-functions????
*/
#include <stdio.h>
int test1();
int test2();
int test3();
int main()
{
printf("%d\n",test1());
printf("%d\n",test2());
printf("%d\n",test3());
return 0;
}
int test1()
{
return 100;
}
int test2()
{
return 200;
}
int test3()
{
return 300;
}
|
|
〔リスト12〕オプションなしで生成されたアセンブラソース(test194.s)
|
.file "test194.c"
.globl __cyg_profile_func_enter
.globl __cyg_profile_func_exit
.section .rodata
.LC0:
.string "%d\n"
.text
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
pushl %ebx
subl $20, %esp
andl $-16, %esp
movl $0, %eax
subl %eax, %esp
movl 4(%ebp), %eax
movl %eax, 4(%esp)
movl $main, (%esp)
call __cyg_profile_func_enter
call test1
movl %eax, 4(%esp)
movl $.LC0, (%esp)
call printf
call test2
movl %eax, 4(%esp)
movl $.LC0, (%esp)
call printf
call test3
movl %eax, 4(%esp)
movl $.LC0, (%esp)
call printf
movl $0, %ebx
movl 4(%ebp), %eax
movl %eax, 4(%esp)
movl $main, (%esp)
call __cyg_profile_func_exit
movl %ebx, %eax
movl -4(%ebp), %ebx
leave
ret
.size main, .-main
.globl test1
.type test1, @function
test1:
pushl %ebp
movl %esp, %ebp
pushl %ebx
subl $20, %esp
movl 4(%ebp), %eax
movl %eax, 4(%esp)
movl $test1, (%esp)
call __cyg_profile_func_enter
movl $100, %ebx
movl 4(%ebp), %eax
movl %eax, 4(%esp)
movl $test1, (%esp)
call __cyg_profile_func_exit
movl %ebx, %eax
addl $20, %esp
popl %ebx
popl %ebp
ret
.size test1, .-test1
.globl test2
.type test2, @function
test2:
pushl %ebp
movl %esp, %ebp
pushl %ebx
subl $20, %esp
movl 4(%ebp), %eax
movl %eax, 4(%esp)
movl $test2, (%esp)
call __cyg_profile_func_enter
movl $200, %ebx
movl 4(%ebp), %eax
movl %eax, 4(%esp)
movl $test2, (%esp)
call __cyg_profile_func_exit
movl %ebx, %eax
addl $20, %esp
popl %ebx
popl %ebp
ret
.size test2, .-test2
.globl test3
.type test3, @function
test3:
pushl %ebp
movl %esp, %ebp
pushl %ebx
subl $20, %esp
movl 4(%ebp), %eax
movl %eax, 4(%esp)
movl $test3, (%esp)
call __cyg_profile_func_enter
movl $300, %ebx
movl 4(%ebp), %eax
movl %eax, 4(%esp)
movl $test3, (%esp)
call __cyg_profile_func_exit
movl %ebx, %eax
addl $20, %esp
popl %ebx
popl %ebp
ret
.size test3, .-test3
.ident "GCC: (GNU) 3.3"
|
|
〔リスト13〕オプション付きで生成されたアセンブラソース(test194a.s)
|
.file "test194.c"
.globl __cyg_profile_func_enter
.globl __cyg_profile_func_exit
.section .rodata
.LC0:
.string "%d\n"
.text
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
pushl %ebx
subl $20, %esp
andl $-16, %esp
movl $0, %eax
subl %eax, %esp
movl 4(%ebp), %eax
movl %eax, 4(%esp)
movl $main, (%esp)
call __cyg_profile_func_enter
call test1
movl %eax, 4(%esp)
movl $.LC0, (%esp)
call printf
call test2
movl %eax, 4(%esp)
movl $.LC0, (%esp)
call printf
call test3
movl %eax, 4(%esp)
movl $.LC0, (%esp)
call printf
movl $0, %ebx
movl 4(%ebp), %eax
movl %eax, 4(%esp)
movl $main, (%esp)
call __cyg_profile_func_exit
movl %ebx, %eax
movl -4(%ebp), %ebx
leave
ret
.size main, .-main
.globl test1
.type test1, @function
test1:
pushl %ebp
movl %esp, %ebp
pushl %ebx
subl $20, %esp
movl 4(%ebp), %eax
movl %eax, 4(%esp)
movl $test1, (%esp)
call __cyg_profile_func_enter
movl $100, %ebx
movl 4(%ebp), %eax
movl %eax, 4(%esp)
movl $test1, (%esp)
call __cyg_profile_func_exit
movl %ebx, %eax
addl $20, %esp
popl %ebx
popl %ebp
ret
.size test1, .-test1
.globl test2
.type test2, @function
test2:
pushl %ebp
movl %esp, %ebp
pushl %ebx
subl $20, %esp
movl 4(%ebp), %eax
movl %eax, 4(%esp)
movl $test2, (%esp)
call __cyg_profile_func_enter
movl $200, %ebx
movl 4(%ebp), %eax
movl %eax, 4(%esp)
movl $test2, (%esp)
call __cyg_profile_func_exit
movl %ebx, %eax
addl $20, %esp
popl %ebx
popl %ebp
ret
.size test2, .-test2
.globl test3
.type test3, @function
test3:
pushl %ebp
movl %esp, %ebp
pushl %ebx
subl $20, %esp
movl 4(%ebp), %eax
movl %eax, 4(%esp)
movl $test3, (%esp)
call __cyg_profile_func_enter
movl $300, %ebx
movl 4(%ebp), %eax
movl %eax, 4(%esp)
movl $test3, (%esp)
call __cyg_profile_func_exit
movl %ebx, %eax
addl $20, %esp
popl %ebx
popl %ebp
ret
.size test3, .-test3
.ident "GCC: (GNU) 3.3"
|
|
|