cygwin環境の確認(win7, x64)
$ uname CYGWIN_NT-6.1-WOW64 |
とりあえずhello world
$ cat test01.c #include <stdio.h> main() { printf( "hello world\n" ); } |
コンパイルしてexeの出力と実行
(cygwinでは、出力ファイル名を省略するとa.outではなくa.exeになる)
$ gcc test01.c -o test01.exe $ ./test01.exe hello world |
アセンブラのコードに変換する
$ gcc -S test01.c $ cat test01.s .file "test01.c" .def ___main; .scl 2; .type 32; .endef .section .rdata,"dr" LC0: .ascii "hello world\0" .text .globl _main .def _main; .scl 2; .type 32; .endef _main: pushl %ebp movl %esp, %ebp andl $-16, %esp subl $16, %esp call ___main movl $LC0, (%esp) call _puts leave ret .def _puts; .scl 2; .type 32; .endef |
objの作成(出力ファイル名を指定しないとa.outになる)
as -o test01.o test01.s |
リンク
gcc -o a.exe test01.o |
実行
./a.exe hello world |
objファイルのダンプ
$ od a.out 0000000 000514 000003 000000 000000 000214 000000 000010 000000 0000020 000000 000405 072056 074145 000164 000000 000000 000000 0000040 000000 000000 000000 000000 000000 000000 000000 000000 0000060 000000 000000 000000 000000 000040 060060 062056 072141 0000100 000141 000000 000000 000000 000000 000000 000000 000000 0000120 000000 000000 000000 000000 000000 000000 000000 000000 0000140 000100 140060 061056 071563 000000 000000 000000 000000 0000160 000000 000000 000000 000000 000000 000000 000000 000000 0000200 000000 000000 000000 000000 000200 140060 063056 066151 0000220 000145 000000 000000 000000 177776 000000 000547 060546 0000240 062553 000000 000000 000000 000000 000000 000000 000000 0000260 072056 074145 000164 000000 000000 000000 000001 000000 0000300 000403 000000 000000 000000 000000 000000 000000 000000 0000320 000000 000000 062056 072141 000141 000000 000000 000000 0000340 000002 000000 000403 000000 000000 000000 000000 000000 0000360 000000 000000 000000 000000 061056 071563 000000 000000 0000400 000000 000000 000003 000000 000403 000000 000000 000000 0000420 000000 000000 000000 000000 000000 000000 000004 000000 0000440 |
ELFデータのダンプ
cygwinで作成されるバイナリはELF形式じゃないので怒られる
$ readelf -S a.out readelf: Error: Not an ELF file - it has the wrong magic bytes at the start |
依存しているライブラリの確認
$ ldd a.exe ntdll.dll => /cygdrive/c/Windows/SysWOW64/ntdll.dll (0x77510000) kernel32.dll => /cygdrive/c/Windows/syswow64/kernel32.dll (0x74c80000) KERNELBASE.dll => /cygdrive/c/Windows/syswow64/KERNELBASE.dll (0x75160000) cygwin1.dll => /usr/bin/cygwin1.dll (0x61000000) ??? => ??? (0x530000) |
関連記事
コメントを残す