前のページ | 次のページ
リスト


〔リスト1〕Cのシンボルが表現される方法を強制的に変更する例test195.c)
void    test(void);
int     main(void)
{
        test();
        return 0;
}
void	test(void)
{
	char	a;
	a='a';
}


〔リスト2〕オプションを付けて生成されたアセンブラソースtest195a.s)
		.file	"test195.c"
	.text
.globl _main
	.type	_main, @function
_main:
	pushl	%ebp
	movl	%esp, %ebp
	subl	$8, %esp
	andl	$-16, %esp
	movl	$0, %eax
	subl	%eax, %esp
	call	_test
	movl	$0, %eax
	leave
	ret
	.size	_main, .-_main
.globl _test
	.type	_test, @function
_test:
	pushl	%ebp
	movl	%esp, %ebp
	subl	$4, %esp
	movb	$97, -1(%ebp)
	leave
	ret
	.size	_test, .-_test
	.ident	"GCC: (GNU) 3.3"

〔リスト3〕オプションなしで生成されたアセンブラソースtest195b.s)
		.file	"test195.c"
	.text
.globl main
	.type	main, @function
main:
	pushl	%ebp
	movl	%esp, %ebp
	subl	$8, %esp
	andl	$-16, %esp
	movl	$0, %eax
	subl	%eax, %esp
	call	test
	movl	$0, %eax
	leave
	ret
	.size	main, .-main
.globl test
	.type	test, @function
test:
	pushl	%ebp
	movl	%esp, %ebp
	subl	$4, %esp
	movb	$97, -1(%ebp)
	leave
	ret
	.size	test, .-test
	.ident	"GCC: (GNU) 3.3"

〔リスト4〕初期化済みでないグローバル変数をオブジェクトファイル中のbssセクションに割り当てる例test196.c
	#include <stdio.h>
void	test1();
int		ix;
int main(int argc, char* argv[])
{
	test1();
	return	0;
}
void	test1()
{
	printf("test1\n);
}


〔リスト5〕オプションを付けて生成されたアセンブラソースtest196a.s)
		.file	"test196.c"
	.text
.globl main
	.type	main, @function
main:
	pushl	%ebp
	movl	%esp, %ebp
	subl	$8, %esp
	andl	$-16, %esp
	movl	$0, %eax
	subl	%eax, %esp
	call	test1
	movl	$0, %eax
	leave
	ret
	.size	main, .-main
	.section	.rodata
.LC0:
	.string	"test1ta
	.text
.globl test1
	.type	test1, @function
test1:
	pushl	%ebp
	movl	%esp, %ebp
	subl	$8, %esp
	movl	$.LC0, (%esp)
	call	printf
	leave
	ret
	.size	test1, .-test1
.globl ix
	.bss
	.align 4
	.type	ix, @object
	.size	ix, 4
ix:
	.zero	4
	.ident	"GCC: (GNU) 3.3"

〔リスト6〕オプションなしで生成されたアセンブラソースtest196b.s)
	.file	"test196.c"
	.text
.globl main
	.type	main, @function
main:
	pushl	%ebp
	movl	%esp, %ebp
	subl	$8, %esp
	andl	$-16, %esp
	movl	$0, %eax
	subl	%eax, %esp
	call	test1
	movl	$0, %eax
	leave
	ret
	.size	main, .-main
	.section	.rodata
.LC0:
	.string	"test1ta
	.text
.globl test1
	.type	test1, @function
test1:
	pushl	%ebp
	movl	%esp, %ebp
	subl	$8, %esp
	movl	$.LC0, (%esp)
	call	printf
	leave
	ret
	.size	test1, .-test1
	.comm	ix,4,4
	.ident	"GCC: (GNU) 3.3"

〔リスト7〕スタックの巻き戻しをさせる例test197.c)
	#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int	test1();
int	test2();
int main(int argc, char* argv[])
{
	printf("%d\n",test1());
	printf("%d\n",test2());
	return	0;
}
int	test1()
{
	return	100;
}
int	test2()
{
	return	200;
}

〔リスト8〕オプションを付けて生成されたアセンブラソースtest197a.s)
		.file	"test197.c"
	.section	.rodata
.LC0:
	.string	"%dodata
	.text
.globl main
	.type	main, @function
main:
.LFB3:
	pushl	%ebp
.LCFI0:
	movl	%esp, %ebp
.LCFI1:
	subl	$8, %esp
.LCFI2:
	andl	$-16, %esp
	movl	$0, %eax
	subl	%eax, %esp
	call	test1
	movl	%eax, 4(%esp)
	movl	$.LC0, (%esp)
	call	printf
	call	test2
	movl	%eax, 4(%esp)
	movl	$.LC0, (%esp)
	call	printf
	movl	$0, %eax
	leave
	ret
.LFE3:
	.size	main, .-main
.globl test1
	.type	test1, @function
test1:
.LFB5:
	pushl	%ebp
.LCFI3:
	movl	%esp, %ebp
.LCFI4:
	movl	$100, %eax
	popl	%ebp
	ret
.LFE5:
	.size	test1, .-test1
.globl test2
	.type	test2, @function
test2:
.LFB7:
	pushl	%ebp
.LCFI5:
	movl	%esp, %ebp
.LCFI6:
	movl	$200, %eax
	popl	%ebp
	ret
.LFE7:
	.size	test2, .-test2
	.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:
.LSFDE3:
	.long	.LEFDE3-.LASFDE3
.LASFDE3:
	.long	.LASFDE3-.Lframe1
	.long	.LFB5
	.long	.LFE5-.LFB5
	.byte	0x4
	.long	.LCFI3-.LFB5
	.byte	0xe
	.uleb128 0x8
	.byte	0x85
	.uleb128 0x2
	.byte	0x4
	.long	.LCFI4-.LCFI3
	.byte	0xd
	.uleb128 0x5
	.align 4
.LEFDE3:
.LSFDE5:
	.long	.LEFDE5-.LASFDE5
.LASFDE5:
	.long	.LASFDE5-.Lframe1
	.long	.LFB7
	.long	.LFE7-.LFB7
	.byte	0x4
	.long	.LCFI5-.LFB7
	.byte	0xe
	.uleb128 0x8
	.byte	0x85
	.uleb128 0x2
	.byte	0x4
	.long	.LCFI6-.LCFI5
	.byte	0xd
	.uleb128 0x5
	.align 4
.LEFDE5:
	.ident	"GCC: (GNU) 3.3"

〔リスト9〕オプションなしで生成されたアセンブラソースtest197b.s)
	.file	"test197.c"
	.section	.rodata
.LC0:
	.string	"%dodata
	.text
.globl main
	.type	main, @function
main:
	pushl	%ebp
	movl	%esp, %ebp
	subl	$8, %esp
	andl	$-16, %esp
	movl	$0, %eax
	subl	%eax, %esp
	call	test1
	movl	%eax, 4(%esp)
	movl	$.LC0, (%esp)
	call	printf
	call	test2
	movl	%eax, 4(%esp)
	movl	$.LC0, (%esp)
	call	printf
	movl	$0, %eax
	leave
	ret
	.size	main, .-main
.globl test1
	.type	test1, @function
test1:
	pushl	%ebp
	movl	%esp, %ebp
	movl	$100, %eax
	popl	%ebp
	ret
	.size	test1, .-test1
.globl test2
	.type	test2, @function
test2:
	pushl	%ebp
	movl	%esp, %ebp
	movl	$200, %eax
	popl	%ebp
	ret
	.size	test2, .-test2
	.ident	"GCC: (GNU) 3.3"

〔リスト10〕関数の出口と入り口に関数呼び出しを付加する例test198.c)
	#include <stdio.h>
int	test1();
int	test2();
int	test21();
int main(int argc, char* argv[])
{
	printf("%d\n",test1());
	printf("%d\n",test2());
	return	0;
}
int	test1()
{
	return	100;
}
int	test2()
{
	printf("%d\n",test21());
	return	200;
}
int	test21()
{
	return	300;
}
void __cyg_profile_func_enter(void *this_fn,void *call_site) 
__attribute__((no_instrument_function));
void __cyg_profile_func_enter(void *this_fn,void *call_site) 
{
	printf("%p\n",this_fn);
	printf("%p\n",call_site);
}

〔リスト11〕test198のマップファイルtest198.map)
Archive member included because of file (symbol)

/usr/lib/libc_nonshared.a(elf-init.oS)
                              /usr/lib/crt1.o (__libc_csu_init)

Memory Configuration

Name             Origin             Length             Attributes
*default*        0x00000000         0xffffffff

Linker script and memory map

LOAD /usr/lib/crt1.o
LOAD /usr/lib/crti.o
LOAD /usr/local/gccbinutils/lib/gcc-lib/i686-pc-linux-gnu/3.3/crtbegin.o
LOAD /tmp/cc6CRRN2.o
LOAD /usr/local/gccbinutils/lib/gcc-lib/i686-pc-linux-gnu/3.3/libgcc.a
LOAD /usr/local/gccbinutils/lib/gcc-lib/i686-pc-linux-gnu/3.3/libgcc_eh.a
LOAD /usr/lib/libc.so
START GROUP
LOAD /lib/libc.so.6
LOAD /usr/lib/libc_nonshared.a
END GROUP
LOAD /usr/local/gccbinutils/lib/gcc-lib/i686-pc-linux-gnu/3.3/libgcc.a
LOAD /usr/local/gccbinutils/lib/gcc-lib/i686-pc-linux-gnu/3.3/libgcc_eh.a
LOAD /usr/local/gccbinutils/lib/gcc-lib/i686-pc-linux-gnu/3.3/crtend.o
LOAD /usr/lib/crtn.o
                0x080480f4                . = (0x8048000 + SIZEOF_HEADERS)

.interp         0x080480f4       0x13
 *(.interp)
 .interp        0x080480f4       0x13 /usr/lib/crt1.o

.note.ABI-tag   0x08048108       0x20
 .note.ABI-tag  0x08048108       0x20 /usr/lib/crt1.o

.hash           0x08048128       0x30
 *(.hash)
〜以下略〜

〔リスト12〕test198の逆アセンブラリストtest198.txt)
	a.out:     ファイル形式 elf32-i386

セクション .init の逆アセンブル:

080482b0 <_init>:
 80482b0:	55                   	push   %ebp
 80482b1:	89 e5                	mov    %esp,%ebp
 80482b3:	83 ec 08             	sub    $0x8,%esp
 80482b6:	e8 79 00 00 00       	call   8048334 <call_gmon_start>
 80482bb:	e8 e0 00 00 00       	call   80483a0 <frame_dummy>
 80482c0:	e8 db 02 00 00       	call   80485a0 <__do_global_ctors_aux>
 80482c5:	c9                   	leave  
 80482c6:	c3                   	ret    
セクション .plt の逆アセンブル:

080482c8 <.plt>:
 80482c8:	ff 35 ec 96 04 08    	pushl  0x80496ec
 80482ce:	ff 25 f0 96 04 08    	jmp    *0x80496f0
 80482d4:	00 00                	add    %al,(%eax)
 80482d6:	00 00                	add    %al,(%eax)
 80482d8:	ff 25 f4 96 04 08    	jmp    *0x80496f4
 80482de:	68 00 00 00 00       	push   $0x0
 80482e3:	e9 e0 ff ff ff       	jmp    80482c8 <_init+0x18>
 80482e8:	ff 25 f8 96 04 08    	jmp    *0x80496f8
 80482ee:	68 08 00 00 00       	push   $0x8
 80482f3:	e9 d0 ff ff ff       	jmp    80482c8 <_init+0x18>
 80482f8:	ff 25 fc 96 04 08    	jmp    *0x80496fc
 80482fe:	68 10 00 00 00       	push   $0x10
 8048303:	e9 c0 ff ff ff       	jmp    80482c8 <_init+0x18>
セクション .text の逆アセンブル:

08048310 <_start>:
 8048310:	31 ed                	xor    %ebp,%ebp
 8048312:	5e                   	pop    %esi
 8048313:	89 e1                	mov    %esp,%ecx
 8048315:	83 e4 f0             	and    $0xfffffff0,%esp
 8048318:	50                   	push   %eax
 8048319:	54                   	push   %esp
〜以下略〜

〔リスト13〕test198のシンボルリストtest198.lst)
	080480f4 r 
08048108 r 
08048128 r 
08048158 r 
080481c8 r 
08048250 r 
08048260 r 
08048290 r 
08048298 r 
080482b0 t 
080482c8 t 
08048310 t 
080485d0 t 
080485ec r 
080485fc r 
08049600 d 
0804960c d 
080496d4 d 
080496dc d 
080496e4 d 
080496e8 d 
08049704 b 
00000000 ? 
00000000 N 
00000000 N 
00000000 N 
00000000 N 
00000000 N 
00000000 N 
00000000 N 
00000000 a 
00000000 a 
00000000 a 
00000000 a /usr/src/build/231499-i386/BUILD/glibc-2.3.2-20030313/build-i386-linux/config.h
00000000 a /usr/src/build/231499-i386/BUILD/glibc-2.3.2-20030313/build-i386-linux/config.h
00000000 a /usr/src/build/231499-i386/BUILD/glibc-2.3.2-20030313/build-i386-linux/config.h
00000000 a /usr/src/build/231499-i386/BUILD/glibc-2.3.2-20030313/build-i386-linux/config.h
00000000 a /usr/src/build/231499-i386/BUILD/glibc-2.3.2-20030313/build-i386-linux/config.h
00000000 a /usr/src/build/231499-i386/BUILD/glibc-2.3.2-20030313/build-i386-linux/csu/abi-tag.h
00000000 a /usr/src/build/231499-i386/BUILD/glibc-2.3.2-20030313/build-i386-linux/csu/crti.S
00000000 a /usr/src/build/231499-i386/BUILD/glibc-2.3.2-20030313/build-i386-linux/csu/crti.S
00000000 a /usr/src/build/231499-i386/BUILD/glibc-2.3.2-20030313/build-i386-linux/csu/crti.S
00000000 a /usr/src/build/231499-i386/BUILD/glibc-2.3.2-20030313/build-i386-linux/csu/crtn.S
00000000 a /usr/src/build/231499-i386/BUILD/glibc-2.3.2-20030313/build-i386-linux/csu/crtn.S
00000000 a /usr/src/build/231499-i386/BUILD/glibc-2.3.2-20030313/build-i386-linux/csu/crtn.S
00000000 a /usr/src/build/231499-i386/BUILD/glibc-2.3.2-20030313/build-i386-linux/csu/defs.h
00000000 a /usr/src/build/231499-i386/BUILD/glibc-2.3.2-20030313/build-i386-linux/csu/defs.h
00000000 a <built-in>
00000000 a <built-in>
00000000 a <built-in>
00000000 a <built-in>
00000000 a <command line>
00000000 a <command line>
00000000 a <command line>
00000000 a <command line>
00000000 a <command line>
00000000 a <command line>
00000000 a <command line>
00000000 a <command line>
00000000 a <command line>
00000000 a <command line>
00000000 a <command line>
00000000 a <command line>
00000000 a <command line>
〜以下略〜

〔リスト14〕オプションを付けて生成されたアセンブラソースtest198a.s)
		.file	"test198.c"
.globl __cyg_profile_func_enter
.globl __cyg_profile_func_exit
	.section	.rodata
.LC0:
	.string	"%dodata
	.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
	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
	call	test21
	movl	%eax, 4(%esp)
	movl	$.LC0, (%esp)
	call	printf
	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 test21
	.type	test21, @function
test21:
	pushl	%ebp
	movl	%esp, %ebp
	pushl	%ebx
	subl	$20, %esp
	movl	4(%ebp), %eax
	movl	%eax, 4(%esp)
	movl	$test21, (%esp)
	call	__cyg_profile_func_enter
	movl	$300, %ebx
	movl	4(%ebp), %eax
	movl	%eax, 4(%esp)
	movl	$test21, (%esp)
	call	__cyg_profile_func_exit
	movl	%ebx, %eax
	addl	$20, %esp
	popl	%ebx
	popl	%ebp
	ret
	.size	test21, .-test21
	.section	.rodata
.LC1:
	.string	"%podata
	.text
.globl __cyg_profile_func_enter
	.type	__cyg_profile_func_enter, 
@function
__cyg_profile_func_enter:
	pushl	%ebp
	movl	%esp, %ebp
	subl	$8, %esp
	movl	8(%ebp), %eax
	movl	%eax, 4(%esp)
	movl	$.LC1, (%esp)
	call	printf
	movl	12(%ebp), %eax
	movl	%eax, 4(%esp)
	movl	$.LC1, (%esp)
	call	printf
	leave
	ret
	.size	__cyg_profile_func_enter,
 .-__cyg_profile_func_enter
	.ident	"GCC: (GNU) 3.3"

〔リスト15〕オプションなしで生成されたアセンブラソースtest198b.s)
		.file	"test198.c"
	.section	.rodata
.LC0:
	.string	"%dodata
	.text
.globl main
	.type	main, @function
main:
	pushl	%ebp
	movl	%esp, %ebp
	subl	$8, %esp
	andl	$-16, %esp
	movl	$0, %eax
	subl	%eax, %esp
	call	test1
	movl	%eax, 4(%esp)
	movl	$.LC0, (%esp)
	call	printf
	call	test2
	movl	%eax, 4(%esp)
	movl	$.LC0, (%esp)
	call	printf
	movl	$0, %eax
	leave
	ret
	.size	main, .-main
.globl test1
	.type	test1, @function
test1:
	pushl	%ebp
	movl	%esp, %ebp
	movl	$100, %eax
	popl	%ebp
	ret
	.size	test1, .-test1
.globl test2
	.type	test2, @function
test2:
	pushl	%ebp
	movl	%esp, %ebp
	subl	$8, %esp
	call	test21
	movl	%eax, 4(%esp)
	movl	$.LC0, (%esp)
	call	printf
	movl	$200, %eax
	leave
	ret
	.size	test2, .-test2
.globl test21
	.type	test21, @function
test21:
	pushl	%ebp
	movl	%esp, %ebp
	movl	$300, %eax
	popl	%ebp
	ret
	.size	test21, .-test21
	.section	.rodata
.LC1:
	.string	"%podata
	.text
.globl __cyg_profile_func_enter
	.type	__cyg_profile_func_enter, @function
__cyg_profile_func_enter:
	pushl	%ebp
	movl	%esp, %ebp
	subl	$8, %esp
	movl	8(%ebp), %eax
	movl	%eax, 4(%esp)
	movl	$.LC1, (%esp)
	call	printf
	movl	12(%ebp), %eax
	movl	%eax, 4(%esp)
	movl	$.LC1, (%esp)
	call	printf
	leave
	ret
	.size	__cyg_profile_func_enter, .-__cyg_profile_func_enter
	.ident	"GCC: (GNU) 3.3"

〔リスト16〕wchar_t型のサイズを変更する例test199.c)
	/*
 *wchar_tのサイズ
 */
#include <stdio.h>
int main(int argc, char* argv[])
{
	wchar_t	data	=	0;
	printf("wchar_tのサイズは%dです\n",sizeof(data));
	return	0;
}

〔リスト17〕オプションを付けて生成されたアセンブラソースtest199a.s)
		.file	"test199.c"
	.section	.rodata
.LC0:
	.string	"wchar_t
	.text
.globl main
	.type	main, @function
main:
	pushl	%ebp
	movl	%esp, %ebp
	subl	$24, %esp
	andl	$-16, %esp
	movl	$0, %eax
	subl	%eax, %esp
	movw	$0, -2(%ebp)
	movl	$2, 4(%esp)
	movl	$.LC0, (%esp)
	call	printf
	movl	$0, %eax
	leave
	ret
	.size	main, .-main
	.ident	"GCC: (GNU) 3.3"

〔リスト18〕オプションなしで生成されたアセンブラソースtest199b.s)
		.file	"test199.c"
	.section	.rodata
.LC0:
	.string	"wchar_t
	.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	$0, -4(%ebp)
	movl	$4, 4(%esp)
	movl	$.LC0, (%esp)
	call	printf
	movl	$0, %eax
	leave
	ret
	.size	main, .-main
	.ident	"GCC: (GNU) 3.3"

前のページ | 次のページ
NEW記事内インデックス    連載インデックスはこちら   Interfaceのトップ
コード生成規約に対するオプションの補足つづき
◆リスト

Copyright 2004 岸 哲夫

Copyright 1997-2017 CQ Publishing Co.,Ltd.